Format #1: date-month-year
var d = new Date ( ) ;
var curr_date = d . getDate ( ) ;
var curr_month = d . getMonth ( ) ;
var curr_year = d . getFullYear ( ) ;
document . write ( curr_date + "-" + curr_month + "-" + curr_year ) ;
Format #2: month/day/year
var d = new Date ( ) ;
var curr_date = d . getDate ( ) ;
var curr_month = d . getMonth ( ) ;
curr_month ++ ;
var curr_year = d . getFullYear ( ) ;
document . write ( curr_month + "/" + curr_date + "/" + curr_year ) ;
Format #3: date-month name-year (something like, 21-March-2001)
var m_names = new Array ( "January" , "February" , "March" ,
"April" , "May" , "June" , "July" , "August" , "September" ,
"October" , "November" , "December" ) ;
var d = new Date ( ) ;
var curr_date = d . getDate ( ) ;
var curr_month = d . getMonth ( ) ;
var curr_year = d . getFullYear ( ) ;
document . write ( curr_date + "-" + m_names [ curr_month ]
+ "-" + curr_year ) ;
Format #4: Like 21st March 2001
var m_names = new Array ( "January" , "February" , "March" ,
"April" , "May" , "June" , "July" , "August" , "September" ,
"October" , "November" , "December" ) ;
var d = new Date ( ) ;
var curr_date = d . getDate ( ) ;
var sup = "" ;
if ( curr_date == 1 || curr_date == 21 || curr_date == 31 ) {
sup = "st" ;
} else if ( curr_date == 2 || curr_date == 22 ) {
sup = "nd" ;
} else if ( curr_date == 3 || curr_date == 23 ) {
sup = "rd" ;
} else {
sup = "th" ;
}
var curr_month = d . getMonth ( ) ;
var curr_year = d . getFullYear ( ) ;
document . write ( curr_date + "<SUP>" + sup + "</SUP> "
+ m_names [ curr_month ] + " " + curr_year ) ;
Format #5: day date month name year (something like, Wednesday 21st March 2001)
var d_names = new Array ( "Sunday" , "Monday" , "Tuesday" ,
"Wednesday" , "Thursday" , "Friday" , "Saturday" ) ;
var m_names = new Array ( "January" , "February" , "March" ,
"April" , "May" , "June" , "July" , "August" , "September" ,
"October" , "November" , "December" ) ;
var d = new Date ( ) ;
var curr_day = d . getDay ( ) ;
var curr_date = d . getDate ( ) ;
var sup = "" ;
if ( curr_date == 1 || curr_date == 21 || curr_date == 31 ) {
sup = "st" ;
} else if ( curr_date == 2 || curr_date == 22 ) {
sup = "nd" ;
} else if ( curr_date == 3 || curr_date == 23 ) {
sup = "rd" ;
} else {
sup = "th" ;
}
var curr_month = d . getMonth ( ) ;
var curr_year = d . getFullYear ( ) ;
document . write ( d_names [ curr_day ] + " " + curr_date + "<SUP>"
+ sup + "</SUP> " + m_names [ curr_month ] + " " + curr_year ) ;
Format #6: Hours:Minutes (Finding the time)
var d = new Date ( ) ;
var curr_hour = d . getHours ( ) ;
var curr_min = d . getMinutes ( ) ;
document . write ( curr_hour + " : " + curr_min ) ;
Format #7: Correct Time with AM and PM
var a_p = "" ;
var d = new Date ( ) ;
var curr_hour = d . getHours ( ) ;
if ( curr_hour < 12 ) {
a_p = "AM" ;
} else {
a_p = "PM" ;
}
if ( curr_hour == 0 ) {
curr_hour = 12 ;
}
if ( curr_hour > 12 ) {
curr_hour = curr_hour - 12 ;
}
var curr_min = d . getMinutes ( ) ;
document . write ( curr_hour + " : " + curr_min + " " + a_p ) ;
Format #8: Two digit minutes
var a_p = "" ;
var d = new Date ( ) ;
var curr_hour = d . getHours ( ) ;
if ( curr_hour < 12 ) {
a_p = "AM" ;
} else {
a_p = "PM" ;
}
if ( curr_hour == 0 ) {
curr_hour = 12 ;
}
if ( curr_hour > 12 ) {
curr_hour = curr_hour - 12 ;
}
var curr_min = d . getMinutes ( ) ;
curr_min = curr_min + "" ;
if ( curr_min . length == 1 ) {
curr_min = "0" + curr_min ;
}
document . write ( curr_hour + " : " + curr_min + " " + a_p ) ;
Format #9: Finding the number of seconds and milliseconds
var d = new Date ( ) ;
var curr_hour = d . getHours ( ) ;
var curr_min = d . getMinutes ( ) ;
var curr_sec = d . getSeconds ( ) ;
var curr_msec = d . getMilliseconds ( ) ;
document . write ( curr_hour + ":" + curr_min + ":"
+ curr_sec + ":" + curr_msec ) ;
getUTCDate(): Date
getUTCMonth(): Month
getUTCFullYear(): Year (4 digit)
getUTCDay(): Day
getUTCHours(): Hours
getUTCMinutes(): Minutes
getUTCSeconds(): Seconds
getUTCMilliseconds(): Milliseconds
Format #11: with jQuery datepicker
$ . datepicker . formatDate ( 'yy-mm-dd' , new Date ( 2007 , 1 - 1 , 26 ) ) ;