迄今为止的时间戳 jQuery

Timestamp to Date in jQuery

我是 jQuery 的新手,我需要一些基本问题的帮助。

我尝试将 timestamp 值转换为 date

MyDate = new Date(value);

这是输出:

Wed Jan 28 2015 16:26:07 GMT+0200 (IST)

我希望输出为:

28/01/2015 16:26:07

有人可以告诉我该怎么做吗?不幸的是,并没有设法在网上找到它。可能是因为我经验不够。

var d = new Date();
var n = d.toISOString(); 

这将给出以下输出:

2015-01-29T14:27:19.714Z 

如果您想编写更多代码,请尝试使用以下方法:

var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();

您拥有变量中的值,现在可以以您想要的任何格式显示它们。时间也存在类似的方法。

为了更好地处理日期,请考虑使用 Date.js。

分别获取每个部分并像这样写出所需的输出:

function format_date(date) {
  month=date.getMonth();
  month=month+1; //javascript date goes from 0 to 11
  if (month<10) month="0"+month; //adding the prefix

  year=date.getFullYear();
  day=date.getDate();
  hour=date.getHours();
  minutes=date.getMinutes();
  seconds=date.getSeconds();

  return day+"/"+month+"/"+year+" "+hour+":"+minutes+":"+seconds;

}

MyDate = new Date(value);
formatedDate=format_date(MyDate);