在javascript中将2014年11月28日星期五16:00:00 GMT 0530(印度标准时间)转换为2014-

What is the best way of converting Fri Nov 28 2014 16:00:00 GMT 0530 (India Standard Time) to 2014-11-28 16:00:00 in javascript

本文关键字:标准时间 2014- 转换 0530 GMT 28日 11月 2014年 星期五 javascript 中将      更新时间:2023-09-26

Fri Nov 28 2014 16:00:00 GMT 0530 (India Standard Time) to 2014-11-28 16:00:00我希望转换仅在javascript中进行。在 php 中,当我使用

date('Y-m-d H:i:s', strtotime(Wed Nov 26 2014 04:30:00 GMT 0530 (India Standard Time)));给我:1970-01-01 05:30:00

date('Y-m-d H:i:s',time(Wed Nov 26 2014 03:30:00 GMT 0530 (India Standard Time)));给了我2014-11-26 17:32:04

2分4秒是额外的。

谢谢。

var d = new Date("Fri Nov 28 2014 16:00:00 GMT 0530");
console.log(getFormattedString(d));
function getFormattedString(d){
  return d.getFullYear() + "-"+(d.getMonth()+1) +"-"+d.getDate() + ' '+d.toString().split(' ')[4];
  // for time part you may wish to refer http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-string-with-format-hhmmss
}

使用时刻.js

moment().format("YYYY-MM-DD HH:mm:ss")

类似的东西。

但是你应该在这里多挖一点。有很多类似的问题

http://momentjs.com/docs/#/displaying/format/