One js (9) time per day (precise to seconds)

Source: Internet
Author: User
[Javascript] varST & quot; 2010-5-139: 22: 10 & quot;, // start time: ET & quot; 2010-5-& quot ;, // startTimeMyFormatTime (ST ). getTime (), endTimeMyFormatTime (ET ). getTime (); I

[Javascript]
Var ST = "9:22:10", // start time
ET = "9:22:11", // End Time
StartTime = MyFormatTime (ST). getTime (),
EndTime = MyFormatTime (ET). getTime ();
If (startTime> endTime ){
Document. write ("End Time:" + ST + "earlier than start time:" + ET );
} Else if (startTime Document. write ("End Time:" + ET + "greater than the start time:" + ST );
} Else {
Document. write ("End Time:" + ET + "equals to start time:" + ST );
};
Function MyFormatTime (str ){
Var year = str. split ('-') [0];
Var month = str. split ('-') [1];
Var date = str. split ('-') [2]. split ('') [0];
Var h = str. split ('-') [2]. split ('') [1]. split (':') [0];
Var m = str. split ('-') [2]. split ('') [1]. split (':') [1];
Var s = str. split ('-') [2]. split ('') [1]. split (':') [2];
Return new Date (year, month, date, h, m, s );
};

Var ST = "9:22:10", // start time
ET = "9:22:11", // End Time
StartTime = MyFormatTime (ST). getTime (),
EndTime = MyFormatTime (ET). getTime ();
If (startTime> endTime ){
Document. write ("End Time:" + ST + "earlier than start time:" + ET );
} Else if (startTime Document. write ("End Time:" + ET + "greater than the start time:" + ST );
} Else {
Document. write ("End Time:" + ET + "equals to start time:" + ST );
};
Function MyFormatTime (str ){
Var year = str. split ('-') [0];
Var month = str. split ('-') [1];
Var date = str. split ('-') [2]. split ('') [0];
Var h = str. split ('-') [2]. split ('') [1]. split (':') [0];
Var m = str. split ('-') [2]. split ('') [1]. split (':') [1];
Var s = str. split ('-') [2]. split ('') [1]. split (':') [2];
Return new Date (year, month, date, h, m, s );
};

 

Related Article

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.