Sort Array by ISO 8601 date

Sort Lexicographically: As @kdbanman points out, ISO8601See 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’ === true So you would implement: var myArray = [ { name:’oldest’, date:’2007-01-17T08:00:00Z’ }, { name:’newest’, date:’2011-01-28T08:00:00Z’ }, … Read more

Java SimpleDateFormat for time zone with a colon separator?

JodaTime’s DateTimeFormat to rescue: String dateString = “2010-03-01T00:00:00-08:00”; String pattern = “yyyy-MM-dd’T’HH:mm:ssZ”; DateTimeFormatter dtf = DateTimeFormat.forPattern(pattern); DateTime dateTime = dtf.parseDateTime(dateString); System.out.println(dateTime); // 2010-03-01T04:00:00.000-04:00 (time and timezone difference in toString() is just because I’m at GMT-4 and didn’t set locale explicitly) If you want to end up with java.util.Date just use DateTime#toDate(): Date date = dateTime.toDate(); … Read more

Regex to match an ISO 8601 datetime string

For the strict, full datetime, including milliseconds, per the W3C’s take on the spec.: //– Complete precision: /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/ //– No milliseconds: /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)/ //– No Seconds: /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)/ //– Putting it all together: /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/ . Additional variations allowed by the actual ISO 8601:2004(E) doc: /******************************************** ** No time-zone varients: */ //– Complete precision: /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+/ //– No milliseconds: … Read more

Generate RFC 3339 timestamp in Python [duplicate]

UPDATE 2021 In Python 3.2 timezone was added to the datetime module allowing you to easily assign a timezone to UTC. >>> import datetime >>> n = datetime.datetime.now(datetime.timezone.utc) >>> n.isoformat() ‘2021-07-13T15:28:51.818095+00:00’ previous answer: Timezones are a pain, which is probably why they chose not to include them in the datetime library. try pytz, it has … Read more

What does ‘PT’ prefix stand for in Duration?

As can be found on the page Jesper linked to (ISO-8601 – Data elements and interchange formats – Information interchange – Representation of dates and times) P is the duration designator (for period) placed at the start of the duration representation. Y is the year designator that follows the value for the number of years. … Read more

ISO-8601 String to Date in Google Sheets cell

To get an actual Date value which you can format using normal number formatting… =DATEVALUE(MID(A1,1,10)) + TIMEVALUE(MID(A1,12,8)) eg. A B 1 2016-02-22T05:03:21Z 2/22/16 5:03:21 AM Assumes timestamps are in UTC Ignores milliseconds (though you could add easily enough) The DATEVALUE() function turns a formatted date string into a value, and TIMEVALUE() does the same for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)