I know that there are many Javascript libraries that parse and format dates in Javascript, but I would like to use one that allows parse date strings as this:
"sáb, 5 ene 2013 13:21:24 PST"
Which is equivalent to:
"Sat, 5 jan 2013 21:21:24 UTC"
I like moment.js and sugar.js, both of them are good libraries and have support for different locales, but, AFAIK, they don't support timezone in the form: "CES, PST, CET, ...", only the iso format "+01:00".
I've tested many others libraries and the only that fits the requirements is date.js that works fine, but there are 2 things that I don't like about it, the project seems to be abandoned since 2007 and It doesn't support module load with require() because was created for web use and I need it for Titanium Mobile app, so libraries compliant with Node.js fit better.
In other words, I need a Javascript lib that allows me to do this (with their own API methods):
var DateHelper = require('my-date-helper-lib');
var strDate = 'sáb, 5 ene 2013 13:21:24 PST';
console.log(strDate + ' => ' + DateHelper.parse(strDate).toISOFormat());
That code should prints in console something like:
sáb, 5 ene 2013 13:21:24 PST => 2013-01-05 21:21:24+0000
I could modify date.js to use it in my app, but If there is any other library that doesn't need to be touched I prefer it.
Does anyone know any library that fits such requirements ?
Check out the module timezone:
var tz = require('timezone/loaded'),
equal = require('assert').equal,
utc;
// Get POSIX time in UTC.
utc = tz('2012-01-01');
// Convert UTC time to local time in a localize language.
equal(tz(utc, '%c', 'fr_FR', 'America/Montreal'),
'sam. 31 déc. 2011 19:00:00 EST');