Java SimpleDateFormat pattern for W3C XML dates with timezone [duplicate]
If you use Java 7+, this pattern should work (X is for the ISO 8601 time zone): SimpleDateFormat fmt = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ssX”);
If you use Java 7+, this pattern should work (X is for the ISO 8601 time zone): SimpleDateFormat fmt = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ssX”);
Python 3.7+ As of Python 3.7 there is a method datetime.fromisoformat() which is exactly the reverse for isoformat(). Older Python If you have older Python, then this is the current best “solution” to this question: pip install python-dateutil Then… import datetime import dateutil def getDateTimeFromISO8601String(s): d = dateutil.parser.parse(s) return d
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 format and toISOString. Both are correct but the underlying process differs. toISOString converts to a Date object, sets to UTC then uses the … Read more
Everything is fine, try this: new Date(Date.parse(“2011-10-02T23:00+02:00”)).getUTCHours() //21 The date is parsed correctly (taking the timezone into account as expected). However when you simply print Date.toString() it shows the date in current browser timezone (one of the sins of Java Date object shamelessly copied to JavaScript…) If you stick to getUTC*() family of methods you … Read more
UPDATE: The concepts presented here still apply, but the code is outmoded. The Joda-Time project, now in maintenance mode, advises migration to the java.time classes. See the java.time code in the Answer by Szulc. Short Answer DateTime dateTimeStart = new DateTime( “2003-W01-1”, DateTimeZone.UTC ); // Joda-Time 2.4. DateTime dateTimeStop = dateTimeStart.plusWeeks( 1 ); For details, … Read more
tl;dr OffsetDateTime.parse( “2010-12-27T10:50:44.000-08:00” ) ISO 8601 The input string format is defined in the ISO 8601 standard, a family of date-time formats. Avoid old date-time classes The Question and other Answers use old outmoded date-time classes bundled with the earliest versions of Java. Avoid them. Now supplanted by the java.time classes. Using java.time Your input … Read more
Swift3,4,5 implementation: https://github.com/Igor-Palaguta/YoutubeEngine/blob/master/Source/YoutubeEngine/Parser/NSDateComponents%2BISO8601.swift Example: let components = try DateComponents(ISO8601String: “P1Y2M3DT4H5M6S”) Tests: https://github.com/Igor-Palaguta/YoutubeEngine/blob/master/Tests/YoutubeEngineTests/ISO8601DurationTests.swift Update: fixed for DougSwith case “P3W3DT20H31M21”
This is a bug in IsoFields which managed to slip through because this method was untested (sorry about that). There should be very little observable difference between IsoFields and WeekFields.ISO when implemented correctly. See the bug report and patch which will eventually work through the system and be fixed. Note, testing revealed that getting the … Read more
You should probably use the datejs that f3lix recommended, however I was bored and threw together a little object that does exactly what you asked for: September 25, 2012: Cleaned code, allow non-extended format, eg 20120925T164740+0200 December 1, 2011: fixed a bug in the month string. August was missing var ISODate = { convert : … Read more