iso8601

Converting ISO 8601 date time to seconds in Python

筅森魡賤 提交于 2019-11-29 11:50:37
问题 I am trying to add two times together. The ISO 8601 time stamp is '1984-06-02T19:05:00.000Z', and I would like to convert it to seconds. I tried using the Python module iso8601, but it is only a parser. Any suggestions? 回答1: If you want to get the seconds since epoch, you can use python-dateutil to convert it to a datetime object and then convert it so seconds using the strftime method. Like so: >>> import dateutil.parser as dp >>> t = '1984-06-02T19:05:00.000Z' >>> parsed_t = dp.parse(t) >>>

Java Time's week-of-week-based-year pattern parsing with DateTimeFormatter

喜你入骨 提交于 2019-11-29 11:06:35
I need to output the current date in the format week-based-year - week-of-week-based-year , i.e. using the ISO week date where the week always starts on a Monday and the first week of the year is the first one that has at least four days in January (so the week with the first Thursday in January). Since 31 December 2015 was a Thursday, the Friday through Sunday, i.e. 1st through 3rd of January 2016, all belong in the 53rd week of 2015 (a "long year"), and the first week of 2016 starts on Monday, 4 January. From the DateTimeFormatter spec , I would have expected that I can just use the pattern

How to output date in javascript in ISO 8601 without milliseconds and with Z

喜你入骨 提交于 2019-11-29 10:34:38
问题 Here is a standard way to serialise date as ISO 8601 string in JavaScript: var now = new Date(); console.log( now.toISOString() ); // outputs '2015-12-02T21:45:22.279Z' I need just the same output, but without milliseconds. How can I output 2015-12-02T21:45:22Z ? 回答1: Simple way: console.log( now.toISOString().split('.')[0]+"Z" ); 回答2: This is the solution: var now = new Date(); var str = now.toISOString(); var res = str.replace(/\.[0-9]{3}/, ''); alert(res); Finds the . (dot) and removes 3

Convert ISO 8601 duration with JavaScript

别来无恙 提交于 2019-11-29 09:52:45
How can I convert duration with JavaScript, for example: PT16H30M crush You could theoretically get an ISO8601 Duration that looks like the following: P1Y4M3W2DT10H31M3.452S I wrote the following regular expression to parse this into groups: (-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)? It's not pretty, and someone better versed in regular expressions might be able to write a better one. The groups boil down into the following: Sign Years Months Weeks Days Hours Minutes Seconds I wrote the following function to convert it into a

How can I store the current timestamp in SQLite as ticks?

梦想与她 提交于 2019-11-29 06:21:37
I have a SQLite database where I store the dates as ticks. I am not using the default ISO8601 format. Let's say I have a table defined as follows: CREATE TABLE TestDate (LastModifiedTime DATETIME) Using SQL, I wish to insert the current date and time. If I execute any of the below statements, I end up getting the date and time stored as a string and not in ticks. INSERT INTO TestDate (LastModifiedTime) VALUES(CURRENT_TIMESTAMP) INSERT INTO TestDate (LastModifiedTime) VALUES(DateTime('now')) I have looked at the SQLite documenation , but I do not seem to find any option to obtain the current

Sort array by ISO 8601 date

隐身守侯 提交于 2019-11-29 01:38:07
how can i sort this array by date (ISO 8601)? var myArray = new Array(); myArray[0] = { name:'oldest', date:'2007-01-17T08:00:00Z' } myArray[1] = { name:'newest', date:'2011-01-28T08:00:00Z' } myArray[2] = { name:'old', date:'2009-11-25T08:00:00Z' } Playground: http://jsfiddle.net/4tUZt/ Thanks in advance! Sort Lexicographically: As @kdbanman points out, ISO8601 See General principles was designed for lexicographical sort. As such the ISO8601 string representation can be sorted like any other string, and this will give the expected order. '2007-01-17T08:00:00Z' < '2008-01-17T08:00:00Z' ===

Can strict JSON $dates be used in a MongoDB query?

落花浮王杯 提交于 2019-11-29 01:28:30
I'm trying to write a date comparison query using MongoDB's strict JSON representation of BSON . I'd like it to work in the MongoDB shell (v2.4.3) Here's what I've tried... Setup: create a new document with an at date of Jan 1, 2020 > db.myTimes.insert({"at": new Date("2020-01-01")}) Using non-strict query for date > 2010, no problem: > db.myTimes.find({"at": {"$gt": new Date("2010-01-01")}}) { "_id" : ObjectId([snipped]), "at" : ISODate("2020-01-01T00:00:00Z") } Using strict JSON query, however... NO DICE > db.myTimes.find({"at": {"$gt": {"$date":"2010-01-01T00:00:00Z"}}}) > db.myTimes.find({

Turn postgres date representation into ISO 8601 string

会有一股神秘感。 提交于 2019-11-28 21:12:19
I'm trying to format a Postgres date representation into a ISO 8601 string. I'm assuming that there is a Postgres function that can do it, but I found the documentation short on examples. My query is SELECT now()::timestamp which returns [{{2016, 8, 9}, {3, 56, 55, 754181}}] I'm trying to get the date into a format that looks more like 2016-8-9T03:56:55+00:00 . What changes do I need to make to my query to make that happen? Thanks for your help. I think I found a way to do the formatting, but it's not ideal because I'm writing the formatting myself. Here is a potential solution: SELECT to_char

How to convert Python's .isoformat() string back into datetime object [duplicate]

霸气de小男生 提交于 2019-11-28 17:42:19
This question already has an answer here: Convert timestamps with offset to datetime obj using strptime 4 answers How do I parse an ISO 8601-formatted date? 25 answers So in Python 3, you can generate an ISO 8601 date with .isoformat(), but you can't convert a string created by isoformat() back into a datetime object because Python's own datetime directives don't match properly. That is, %z = 0500 instead of 05:00 (which is produced by .isoformat()). For example: >>> strDate = d.isoformat() >>> strDate '2015-02-04T20:55:08.914461+00:00' >>> objDate = datetime.strptime(strDate,"%Y-%m-%dT%H:%M:

How do I format a date as ISO 8601 in moment.js?

痞子三分冷 提交于 2019-11-28 16:07:47
This docs mention moment.ISO_8601 as a formatting option (from 2.7.0 - http://momentjs.com/docs/#/parsing/special-formats/ ), but neither of these work (even 2.7.0): var date = moment(); date.format(moment.ISO_8601); // error moment.format(date, moment.ISO_8601); // error ( http://jsfiddle.net/b3d6uy05/1/ ) How can I get an ISO 8601 from moment.js? cyberwombat moment().toISOString(); // or format() - see below http://momentjs.com/docs/#/displaying/as-iso-string/ Update Based on the answer: by @sennet and the comment by @dvlsg (see Fiddle ) it should be noted that there is a difference between