Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does javascript timestamp mean?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces the meaning of javascript timestamp, which is very detailed and has certain reference value. Friends who are interested must finish reading it.

In javascript, the time stamp (timestamp) is the total number of seconds since 00:00:00 GMT on January 1, 1970 (midnight in UTC/GMT). A timestamp is usually a sequence of characters that uniquely identifies the time of a moment.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

What's the time stamp?

The time stamp (timestamp) refers to the total number of seconds since 00:00:00 Greenwich time on January 1, 1970 (midnight in UTC/GMT, that is, 08:00:00 on January 1, 1970 Beijing time).

A timestamp is usually a sequence of characters that uniquely identifies the time of a moment.

The date is converted to a time stamp var date = new Date ('2014-04-23 18 var time1 55 date.getTime 49123'); / / there are three ways to get / / accurate to millisecond var time3 = date.getTime (); console.log (time1); / / 1398250549123 / accurate to millisecond var time2 = date.valueOf (); console.log (time2); / 1398250549123 / accurate to seconds only, millisecond instead of var time3 = Date.parse (date); console.log (time3) / / 1398250549000 timestamp converted to date

Function formatDate (date) {var y = date.getFullYear (); var m = date.getMonth () + 1; m = m

< 10 ? '0' + m : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; return y + '-' + m + '-' + d;//这里可以写格式 //输出:2018-03-24}function timestampToTime(timestamp) { var date = new Date(timestamp * 1000);//时间戳为10位需*1000,时间戳为13位的话不需乘1000 var Y = date.getFullYear() + '-'; var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'; var D = date.getDate() + ' '; var h = date.getHours() + ':'; var m = date.getMinutes() + ':'; var s = date.getSeconds(); return Y+M+D+h+m+s;}timestampToTime(1403058804);console.log(timestampToTime(1403058804));//2014-06-18 10:33:24时间戳作用 1、单独比较两个日期大小 function compareDate(date1,date2){ var oDate1 = new Date(date1); var oDate2 = new Date(date2); if(oDate1.getTime() >

ODate2.getTime () {console.log ('date1 big');} else {console.log ('date2 big');}} compareDate ('2018-10-27)

2. Compare the 24 hours of the day separately.

Function compareTime (T1 ~ T2) {var date = new Date (); var a = t1.split (":"); var b = t2.split (":"); return date.setHours (a [0], a [1]) > date.setHours (b [0], b [1]);} console.log ("12:00", "11:15"))

3. Compare the date plus the time

/ / compare date, time size function compareCalendar (startDate, endDate) {if (startDate.indexOf ("")! =-1 & & endDate.indexOf ("")! =-1) {/ / contains time, date compareTime (startDate, endDate);} else {/ / contains no time, only date compareDate (startDate, endDate) }} function compareDate (checkStartDate, checkEndDate) {var arys1= new Array (); var arys2= new Array (); if (checkStartDate! = null & & checkEndDate! = null) {arys1=checkStartDate.split ('-'); var sdate=new Date (arys1 [0], parseInt (arys1 [1]-1), arys1 [2]); arys2=checkEndDate.split ('-') Var edate=new Date (arys2 [0], parseInt (arys2 [1]-1), arys2 [2]); if (sdate > edate) {alert ("date start time is greater than end time"); return false;} else {alert ("pass"); return true } function compareTime (startDate, endDate) {if (startDate.length > 0 & & endDate.length > 0) {var startDateTemp = startDate.split (""); var endDateTemp = endDate.split (""); var arrStartDate = startDateTemp [0] .split ("-"); var arrEndDate = endDateTemp [0] .split ("-") Var arrStartTime = startDateTemp [1] .split (":"); var arrEndTime = endDateTemp [1] .split (":"); var allStartDate = new Date (arrStartDate [0], arrStartDate [1], arrStartDate [2], arrStartTime [0], arrStartTime [1], arrStartTime [2]); var allEndDate = new Date (arrEndDate [0], arrEndDate [1], arrEndDate [2], arrEndTime [0], arrEndTime [1], arrEndTime [2]) If (allStartDate.getTime () > = allEndDate.getTime ()) {alert ("startTime cannot be greater than endTime, cannot pass"); return false;} else {alert ("startTime is less than endTime, so passed"); return true;}} else {alert ("time cannot be empty") Return false;}} above is all the content of this article "what is the meaning of javascript timestamp?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report