Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

Show date-tme, 5 formats


// Sun Mar 06 2005 09:14:43 GMT-0600 (Central Standard Time).
< SCRIPT >
document.write( Date () + "." )
</ SCRIPT >


// March 6, 2005
< SCRIPT LANGUAGE = "JavaScript1.2" >
var months = new Array (13);
months[1] = "January" ;
months[2] = "February" ;
months[3] = "March" ;
months[4] = "April" ;
months[5] = "May" ;
months[6] = "June" ;
months[7] = "July" ;
months[8] = "August" ;
months[9] = "September" ;
months[10] = "October" ;
months[11] = "November" ;
months[12] = "December" ;
var time = new Date ();
var lmonth = months[time.getMonth() + 1];
var date = time.getDate();
var year = time.getYear();
if (year < 2000)     // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
document.write( "<center>" + lmonth + " " );
document.write(date + ", " + year + "</center>" );
</ SCRIPT >


//  Sunday, March 06, 2005
< script >
var mydate = new Date ()
var year = mydate.getYear()
if (year < 1000)
year += 1900
var day = mydate.getDay()
var month = mydate.getMonth()
var daym = mydate.getDate()
if (daym < 10)
daym = "0" + daym
var dayarray = new Array ( "Sunday" , "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" )
var montharray = new Array ( "January" , "February" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December" )
document.write( "<small><font color='000000' face='Arial'><b>" + dayarray[day] + ", " + montharray[month] + " " + daym + ", " + year + "</b></font></small>" )
</ script >


// 2005/03/06
< script >
var mydate = new Date ()
var year = mydate.getYear()
if (year < 1000)
year += 1900
var day = mydate.getDay()
var month = mydate.getMonth() + 1
if (month < 10)
month = "0" + month
var daym = mydate.getDate()
if (daym < 10)
daym = "0" + daym
document.write( "<small><font color='000000' face='Arial'><b>" + year + "/" + month + "/" + daym + "</b></font></small>" )
</ script >

// 03/06/2005
< script >
var mydate = new Date ()
var year = mydate.getYear()
if (year < 1000)
year += 1900
var day = mydate.getDay()
var month = mydate.getMonth() + 1
if (month < 10)
month = "0" + month
var daym = mydate.getDate()
if (daym < 10)
daym = "0" + daym
document.write( "<small><font color='000000' face='Arial'><b>" + month + "/" + daym + "/" + year + "</b></font></small>" )
</ script >