Home > Web Front-end > JS Tutorial > body text

Things about js datetime_javascript skills

WBOY
Release: 2016-05-16 17:59:21
Original
1267 people have browsed it
Copy code The code is as follows:

//Put a date string such as "2007-2-28 10 :18:30" converted to Date object
var strArray=str.split(" ");
var strDate=strArray[0].split("-");
var strTime=strArray[1 ].split(":");
var a=new Date(strDate[0],(strDate[1]-parseInt(1)),strDate[2],strTime[0],strTime[1], strTime[2])

2: The second method is really simple
var s = "2005-12-15 09:41:30";
var d = new Date (Date.parse(s.replace(/-/g, "/")));
-------------------------- -------------------------------------
Get current time reference:
http ://www.quackit.com/javascript/javascript_date_and_time_functions.cfm
http://www.quackit.com/javascript/tutorial/javascript_date_and_time.cfm

var myDate = new Date();
var year=myDate.getYear(); //Get the current year (2 digits)
var year1=myDate.getFullYear(); //Get the complete year (4 digits, 1970-????)
var moonth=myDate.getMonth(); //Get the current month (0-11, 0 represents January)
myDate.getDate(); //Get the current day (1-31)
myDate.getDay (); //Get the current week ; //Get the current number of hours (0-23)
myDate.getMinutes(); //Get the current number of minutes (0-59)
myDate.getSeconds(); //Get the current number of seconds (0- 59)
myDate.getMilliseconds(); //Get the current milliseconds (0-999)
var mytime=myDate.toLocaleDateString(); //Get the current date//How is it in English?
var mytime =myDate.toLocaleTimeString(); //Get the current time
var a=myDate.toLocaleString( ); //Get the date and time
----------------- -----------------------------
How to determine whether it is datetime type in js
1 Short time, in the form of (13: 04:06)


function isTime(str)
{
var a = str.match(/^(d{1,2})(:)?(d{1,2})2(d{1,2})$/);
if (a == null) {alert('The input parameter is not in the time format'); return false;}
if (a[1]>24 || a[3]>60 || a[4] >60)
{
alert("Incorrect time format");
return false
}
return true;
}


2. Short date, in the form of (2008-07-22)


function strDateTime(str)
{
var r = str.match(/^(d{1,4})(-|/)(d{1,2})2(d{1,2} )$/);
if(r==null)return false;
var d= new Date(r[1], r[3]-1, r[4]);
return ( d.getFullYear()==r[1]&&(d.getMonth() 1)==r[3]&&d.getDate()==r[4]);
}


3 long time, shaped like (2008-07-22 13:04:06)


function strDateTime(str)
{
var reg = /^(d{1,4})(-|/)(d{1,2})2(d{ 1,2}) (d{1,2}):(d{1,2}):(d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7] );
return (d.getFullYear()==r[1]&&(d.getMonth() 1)==r[3]&&d.getDate()==r[4]&&d.getHours()= =r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template