A small example of a date converted to a timestamp in JavaScript _javascript tips

Source: Internet
Author: User

Copy Code code as follows:

/**
* Date into time stamp
* Date format 2011-02-02 21:12:13
* TIME_STR: Date period 2011-02-02
* Fix_time: Time period 21:12:13
*/
function Strtotime (TIME_STR, Fix_time) {
var time = (new Date ()). GetTime ();

if (TIME_STR) {//have date segment
var str = time_str.split ('-');
if (3 = = Str.length) {
var year = parseint (str[0])-0;
var month = parseint (str[1])-0-1;//month is starting from 0
var day = parseint (str[2])-0;

if (fix_time) {//have time period
var fix = Fix_time.split (': ');
if (3 = = Fix.length) {
var hour = parseint (fix[0])-0;
var minute = parseint (fix[1])-0;
var second = parseint (fix[2])-0;
Time = (new Date (year, month, day, hour, minute, second)). GetTime ();
}
} else {
Time = (new Date (year, month, day)). GetTime ();
}
}
}
GetTime () Gets the time stamp to the number of milliseconds
Time = time/1000;//go to number of seconds
return time;
}


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.