Colls,我有一个代码应该创建一个 sToday 变量,它返回像“DD_MM_YYYY_HH_MI_SS”这样的时间戳:
var today = new Date();
var CurrentDay = today.getDay();
var CurrentMonth = today.getMonth();
var CurrentHours = today.getHours();
var CurrentMin = today.getMinutes();
var CurrentSec = today.getSeconds();
if (CurrentDay < 10)
sToday = "0"+today.getDay().toString();
else
sToday = today.getDay().toString();
if(CurrentMonth<10)
sToday += "_0"+today.getMonth().toString();
else
sToday += "_"+today.getMonth().toString();
sToday += "_"+today.getYear().toString();
if (CurrentHours<10)
sToday += "_0"+today.getHours().toString();
else
sToday += "_"+today.getHours().toString();
if (CurrentMin<10)
sToday += "_0"+today.getMinutes().toString();
else
sToday += "_"+today.getMinutes().toString();
if (CurrentSec<10)
sToday += "_0"+today.getSeconds().toString();
else
sToday += "_"+today.getSeconds().toString();
但是当我在 13.04.2012 20:20:14 (我的电脑时间)运行它时,我会收到 05_03_2012_20_20_14 。如何解决此问题并接收 13_04_2012_20_20_14 ?