Date of JavaScript favorites

Source: Internet
Author: User


<SCRIPT type = "text/JavaScript">
// Gettime () indicates the number of seconds since January 1 ,.
VaR n = new date ();
VaR t = n. getfullyear ();
// Document. write ('my time: '+ N. getfullyear () + ''+ N. getmonth () + ''+ N. getdate () + ''+ N. getday () + ''' n. gethours () + ''+ N. getminutes () + ''+ N. getseconds ());
Document. Write ('<br> ');
Document. Write (t );
Document. Write ('<br> ');

Function printtime (SECs ){
VaR Sep = ':';
VaR hours, minutes, seconds, time;
VaR now = new date ();
Hours = now. gethours ();
If (hours <12 ){
Meridiem = 'am ';
} Else {
Meridiem = 'pm ';
}
Hours = hours % 12;
If (hours = 0 ){
Hours = 12;
}
Time = hours;
Minutes = now. getminutes ();
If (minutes <10) {// it cannot be changed to 10 !!!!!!!!!!!!!!!!!!!!!!!!
Minutes = '0' + minutes;
}
Time + = Sep + minutes;
If (SECs ){
Seconds = now. getseconds ();
If (seconds <10 ){
Seconds = '0' + seconds;
}
Time + = Sep + seconds;
}
Return time + ''+ meridiem;

}
// New date (), '% N/% d/% y'
Function datestring (date, string ){
VaR year = date. getfullyear ();
VaR month = date. getmonth ();
VaR realmonth = month + 1;
VaR fillmonth = realmonth;
If (realmonth <10 ){
Fillmonth = '0' + fillmonth;
}
VaR months = ['january ', 'february', 'march', '0000l', 'may', 'june', 'july', 'August ', 'September ', 'October ', 'november', 'december'];
VaR monthname = months [parseint (month, 10)-1];

VaR day = date. getdate ();
VaR filldate = Day;
If (day <10 ){
Filldate = '0' + Day;
}
VaR weekday = date. getday ();
VaR weekdays = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'Friday', 'saturday'];
VaR dayname = weekdays [weekday];

String = string. Replace (/% Y/g, year );
String = string. Replace (/% Y/g, year. tostring (). Slice (-2); // the last two digits of the year
String = string. Replace (/% M/G, monthname );
String = string. Replace (/% M/G, monthname. Slice (0, 3 ));
String = string. Replace (/% N/g, fillmonth );
String = string. Replace (/% N/g, realmonth );
String = string. Replace (/% W/g, dayname );
String = string. Replace (/% M/G, dayname. Slice (0, 3 ));
String = string. Replace (/% d/g, filldate );
String = string. Replace (/% d/g, Day );

Return string;
}


Document. Write ('<br> ');
Document. Write (printtime (true ));
Document. Write ('<br> ');
Document. Write (datestring (new date (), 'Today is % W, % m % d, % y '));
</SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.