Colls, I have a code which should create a sToday variable which returns timestamp like “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();
But when I run it 13.04.2012 20:20:14 (my pc time) then I receive 05_03_2012_20_20_14 .
How to fix this and receive 13_04_2012_20_20_14 ?
getDatereturns the date 1-31.getDayreturns the day of the week 0-6, with 0 being Sunday.getMonthreturns the month 0-11, so you need to add 1 to that value.Instead of printing Date, Month, right now, you’re printing Day, Month – 1.
Alter your code to this: