Convert String ISO-8601 date to oracle’s timestamp datatype

The date format model elements are listed in the Datetime Format Models documentation: SELECT to_timestamp_tz (‘2014-09-12T11:53:06+00:00’, ‘YYYY-MM-DD”T”HH24:MI:SSTZH:TZM’) FROM DUAL TO_TIMESTAMP_TZ(‘2014-09-12T11:53:06+00:00′,’YYYY-MM-DD”T”HH24:MI:SSTZH:TZM’) ————————————————————————— 12-SEP-14 +00:00 The fixed T can be included as a character literal: You can include these characters in a date format model: Punctuation such as hyphens, slashes, commas, periods, and colons Character literals, … 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

Regex and ISO8601 formatted DateTime [duplicate]

Incomplete Regex It’s incomplete as it matches invalid date such as 2013-99-99T04:13:00+00:00. Better solution The regex below won’t match this kind of invalid date (cf. ISO 8601 Date Validation That Doesn’t Suck). You can test with the following code : re = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/ var testDates = { ‘date’ : “2012-10-06T04:13:00+00:00”, ‘validDate’ : “0785-10-10T04:13:00+00:00”, ‘invalidDate’ : … Read more

ISO time (ISO 8601) in Python

Local to ISO 8601: import datetime >>> 2020-03-20T14:28:23.382748 UTC to ISO 8601: import datetime datetime.datetime.utcnow().isoformat() >>> 2020-03-20T01:30:08.180856 Local to ISO 8601 without microsecond: import datetime >>> 2020-03-20T14:30:43 UTC to ISO 8601 with TimeZone information (Python 3): import datetime datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat() >>> 2020-03-20T01:31:12.467113+00:00 UTC to ISO 8601 with Local TimeZone information without microsecond (Python 3): import datetime >>> 2020-03-20T14:31:43+13:00 Local to … 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 = >>> 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

How do I get an ISO 8601 date on iOS?

Use NSDateFormatter: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@”en_US_POSIX”]; [dateFormatter setLocale:enUSPOSIXLocale]; [dateFormatter setDateFormat:@”yyyy-MM-dd’T’HH:mm:ssZZZZZ”]; [dateFormatter setCalendar:[NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian]]; NSDate *now = [NSDate date]; NSString *iso8601String = [dateFormatter stringFromDate:now]; And in Swift: let dateFormatter = DateFormatter() let enUSPosixLocale = Locale(identifier: “en_US_POSIX”) dateFormatter.locale = enUSPosixLocale dateFormatter.dateFormat = “yyyy-MM-dd’T’HH:mm:ssZZZZZ” dateFormatter.calendar = Calendar(identifier: .gregorian) let iso8601String = … 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

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