Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript 时间距离计算 (天,时 ,分,秒) #9

Open
zhulinpinyu opened this issue Aug 2, 2018 · 0 comments
Open

JavaScript 时间距离计算 (天,时 ,分,秒) #9

zhulinpinyu opened this issue Aug 2, 2018 · 0 comments

Comments

@zhulinpinyu
Copy link
Owner

zhulinpinyu commented Aug 2, 2018

const now = new Date();

//2035-6-7 9:00
const endTime = new Date(2035, 5, 7, 9);
const t = endTime - now;
const day = ~~(t / 1000 / 60 / 60 / 24);
const hour = ~~(t / 1000 / 60 / 60 % 24);
const minutes = ~~(t / 1000 / 60 % 60);
const seconds = ~~(t / 1000 % 60);

Thanks
http://baby.justjavac.com/
https://github.com/justjavac/baby-time/blob/master/index.html
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Syntax

@zhulinpinyu zhulinpinyu changed the title JavaScript 时间距离计算 JavaScript 时间距离计算 (精确到天) Aug 2, 2018
@zhulinpinyu zhulinpinyu changed the title JavaScript 时间距离计算 (精确到天) JavaScript 时间距离计算 (天,时 ,分,秒) Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant