Converting timezone-aware datetime to local time in Python

In general, to convert an arbitrary timezone-aware datetime to a naive (local) datetime, I’d use the pytz module and astimezone to convert to local time, and replace to make the datetime naive: In [76]: import pytz In [77]: est=pytz.timezone(‘US/Eastern’) In [78]: d.astimezone(est) Out[78]: datetime.datetime(2010, 10, 30, 13, 21, 12, tzinfo=<DstTzInfo ‘US/Eastern’ EDT-1 day, 20:00:00 DST>) … Read more

How to parse ISO 8601 into date and time format using Moment js in Javascript?

With moment.js var str=”2011-04-11T10:20:30Z”; var date = moment(str); var dateComponent = date.utc().format(‘YYYY-MM-DD’); var timeComponent = date.utc().format(‘HH:mm:ss’); console.log(dateComponent); console.log(timeComponent); <script src=”https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.1/moment.min.js”></script> Or simply with string manipulation var str=”2011-04-11T10:20:30Z”; var parts = str.slice(0, -1).split(‘T’); var dateComponent = parts[0]; var timeComponent = parts[1]; console.log(dateComponent); console.log(timeComponent);

Identifying time zones in ISO 8601

Update: There’s now a draft IETF proposal to extend RFC3339 with the time zone identifier in square brackets, among other things: https://datatracker.ietf.org/doc/draft-ietf-sedate-datetime-extended/ Original Answer: I understand these are not supported by ISO 8601, correct? Correct. ISO-8601 does not concern itself with time zone identifiers. IANA/Olson TZ names are not a “standard”. They are just the … Read more

Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate?

I have a similiar but slightly more complex problem, and I’ve found a very simple solution! The problem: My incoming ISO8601 dates look like this: 2006-06-14T11:06:00+02:00 They have a timezone offset at the end. The solution: Use Peter Hosey’s ISO8601DateFormatter which you can download from here. ISO8601DateFormatter *formatter = [[ISO8601DateFormatter alloc] init]; NSDate *theDate = … Read more

What’s the difference between datetime in ISO 8601 and UTC formats in javascript?

They’re for different purposes. UTC is the primary time standard by which the world regulates clocks and time. ISO is standard format time. ISO also supports ms in its format. So if you want to send data to the server, send the ISO, because ISO is the standard format: var date = new Date(); sendDate(date.toISOString()); … 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

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