Convert EDT timestamp to PST with regex / JavaScript -


a third party providing me edt time-stamp in following format:

mm/dd/yyyy hh:mm

for instance: '08/19/2013 11:31'

i need convert pst javascript (same date time format) , have been looking on can't find info doing this.. if can me example code appreciate it.

if wanted manually, can try following:

  1. split space, have date , time.
  2. split time ":" , split date "/".
  3. create new date() , provide right values in right order.
  4. subtract 3 hours using proper methods, recreate format.

here's example of this:

var est = "01/01/2014 02:31",     finaldate, pst;  finaldate = parsedatestring(est); finaldate.sethours(finaldate.gethours() - 3); pst = formatdate(finaldate);  console.log(pst);  function parsedatestring(str) {     var datetime, date, time, datesplit, month, day, year, timesplit, hour, minute;      datetime = est.split(" ");     date = datetime[0];     time = datetime[1];      datesplit = date.split("/");     month = datesplit[0] - 1;     day = datesplit[1];     year = datesplit[2];      timesplit = time.split(":");     hour = timesplit[0];     minute = timesplit[1];      return new date(year, month, day, hour, minute); }  function formatdate(d) {     return padzero(d.getmonth() + 1) + "/" + padzero(d.getdate()) + "/" + d.getfullyear() + " " + padzero(d.gethours()) + ":" + padzero(d.getminutes()); }  function padzero(num) {     if (+num < 10) {         num = "0" + num;     }     return "" + num; } 

demo: http://jsfiddle.net/mmvmr/

the padzero function there prepend 0s in case number less 10.

reference:


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -