- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
var currentDate = new Date();
var currentDay = currentDate.getDay();
var currentMonth = currentDate.getMonth();
var currentYear = currentDate.getYear();
var currentHour = currentDate.getHours();
var currentMinute = currentDate.getMinutes();
var currentSecond = currentDate.getSeconds();
if (currentMonth < 10) {
currentMonth = '0' + currentMonth;
}
if (currentDay < 10) {
currentDay = '0' + currentDay;
}
if (currentHour < 10) {
currentHour = '0' + currentHour;
}
if (currentMinute < 10) {
currentMinute = '0' + currentMinute;
}
if (currentSecond < 10) {
currentSecond = '0' + currentSecond;
}
и первой ссылкой получаю прекрасную реализацию:
http://blog.stevenlevithan.com/archives/date-time-format
while (val.length < len) val = "0" + val;
внутри http://blog.stevenlevithan.com/archives/date-time-format
И где больший говнокод?
Init: function ( time )
{
var Times = {
Day: time.getDay(),
Month: time.getMonth(),
Year: time.getYear(),
Hour: time.getHours(),
Minute: time.getMinutes(),
Second: time.getSeconds()
};
for ( var key in Times )
{
if ( key > 10 ) key = '0' + key;
}
return Times;
}
}
var Date = MyDate.Init( new Date() );
так что все вы тут эти самые )
if ( key > 10 ) key = '0' + key;