简体   繁体   中英

How to determine epoch time range from today to past date, then determine equal amount of past time?

在此处输入图片说明

  • So I know what today is: Thu 14 Jul = 1468523547

  • And I have an alert value for 1 week ago: Thu 07 Jul = 1467918688

  • Now I need my start_epoch (2weeks ago) that would equal the time between today and my alert . So that I can center my graph.

In my case above, I need to determine 1 week ago from the alert .

Timespans could be a week and a half ago, 6 days etc etc

Is there an easy way to accomplish this using momentjs ?

If you do not want to start exactly one week before alert , but keep alert exactly in the middle between start and end (today), then it will be just the same time difference as between alert and end.

difference = end - alert

then subtract difference from alert to get start .

start = alert - difference

That's it. alert will be exactly in the middle of start and end .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM