当前位置:网站首页>About time and time stamp (personal learning notes)

About time and time stamp (personal learning notes)

2020-11-10 18:47:42 My sister is talking nonsense

First answer what it is UTCGMT
UTC: Coordinated universal time , Universal time .( Maybe it's the time for the world to unify )
GMT: Gleneagles time

There are some irregularities in the earth's rotation every day , And it's slowing down . therefore , Greenwich mean time is no longer used as standard time . Now standard time ── Coordinated universal time (UTC)── Provided by the atomic clock .
since 1924 year 2 month 5 The day begins , The Greenwich Observatory sends out timing information to the world every hour .

Feeling is two ways to calculate time , Whatever it is , The return time is different .

One 、javaScript Built in objects for Date

1、 establish

The official website is here
There are four parameters to create . Namely , nothing unix Time stamp Timestamp string Here's the picture .

Return value :( The return is GMT Time object of timing )
Create a new Date The only way to do this is through new The operator , for example :let now = new Date();
If you call it as a regular function ( That is, without new The operator ), Will return a string , Instead of Date object .
image.png
image.png

2. relevant api

To sum up, it is to obtain the year, year and day , Set the year, month and day , obtain UTC Year month day , Set up UTC Year month day .
image.png

Two 、moment.js

1、 analysis

moment()  //  Local mode 
moment.utc() //  yes UTC Pattern 

moment.unix
My understanding is to change a timestamp into a millisecond timestamp

official :moment.unix Output Unix Time stamp ( since Unix Seconds since the epoch )
however js Built-in objects Date Create a millisecond timestamp , Or object , They can be used directly moment(dd) transformation . I don't know the meaning of this function ?
var day2 = moment.unix(1318781876.721);
var day3 = moment.unix(1318781876);
console.log(day3.valueOf()); // 1318781876000
console.log(day2.valueOf()); // 1318781876721

isBefore
Check one moment Is it in another moment Before . The first parameter will be resolved to moment( If not resolved )

startOf
endOf
add

//  Set initial value 
const initQuery: SearchCondition = {
    CreateTs: {
        start: moment()
            .add(-7, "d")
            .startOf("day"),
        end: moment().endOf("day")
    }
};
//  The initial value is seven days ago 00:00:00, The end time is today 23:59:59

Why is there a plus sign here ?
image.png

版权声明
本文为[My sister is talking nonsense]所创,转载请带上原文链接,感谢