java 毫秒到 UNIX 时间戳

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2420288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 21:03:23  来源:igfitidea点击:

Milliseconds to UNIX timestamp

javaandroid

提问by t.vb.w

Anyone have any idea how I would go about converting a timestamp in milliseconds from 1970(from Android's System.currentTimeMillis();) to a UNIX timestamp? It need only be accurate to the day.

任何人都知道我将如何以毫秒为单位将时间戳从1970(来自 Android 的System.currentTimeMillis();)转换为 UNIX 时间戳?它只需要准确到当天。

I figure I could divide by 1000to get seconds, and then divide by 86400(number of seconds in a day) to get the # of days. But I'm not sure where to go from there.

我想我可以除以1000得到秒,然后除以86400(一天中的秒数)得到天数。但我不确定从那里去哪里。

Many thanks.

非常感谢。

回答by thelost

Divide it by 1000

除以 1000

回答by Chris Jester-Young

Dividing by 1000 is enough to get a Unix timestamp. You don't need any numbers of days or anything like that.

除以 1000 就足以获得 Unix 时间戳。你不需要任何天数或类似的东西。

回答by Chirag

long unixTime = System.currentTimeMillis() / 1000L;