时间戳值不正确 - c.getTimeInMills()

时间:2023-04-06
本文介绍了时间戳值不正确 - c.getTimeInMills()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个正常工作的 DatePicker,但是,当我将日期转换为时间戳时,时间戳完全错误.请参阅下面的代码:

I have a DatePicker which is working correctly, however, when I convert the date to a timestamp, the timestamp is completely wrong. Please see my code below:

final Calendar c = Calendar.getInstance();
                int mYear = c.get(Calendar.YEAR); // current year
                int mMonth = c.get(Calendar.MONTH); // current month
                int mDay = c.get(Calendar.DAY_OF_MONTH); // current day
                timestamp = c.getTimeInMillis();

c.getTimeInMillis 部分似乎没有得到正确的日期.有谁知道如何解决这个问题?

The part c.getTimeInMillis does not seem to be getting the correct date. Does anyone know how to fix this?

预计日期是今天,我得到的是 5/31/51128, 4:47:42 PM.我已经弄清楚为什么它显示错误的日期:生成的时间戳末尾有 3 个额外的数字.我不知道为什么,或者如何解决这个问题.

Expected date was today’s date and I'm getting 5/31/51128, 4:47:42 PM. I have figured out why it is showing the wrong date: the generated timestamp has 3 extra digits at the end. I don't know why though, or how to fix this.

推荐答案

我怀疑您正在将 timestamp(以毫秒为单位)提供给需要秒数的例程.那些3 个额外数字"是时间戳的毫秒部分.如果您觉得这听起来不错,请在传递之前将 timestamp 除以 1000.

I suspect you are feeding timestamp, which is in milliseconds, to a routine that wants seconds. Those "3 extra digits" are the milliseconds part of the timestamp. If this sounds right to you, divide timestamp by 1000 before passing it on.

这篇关于时间戳值不正确 - c.getTimeInMills()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在android中将时间戳转换为当前日期 下一篇:将 Date 对象与 Java 中的 TimeStamp 进行比较

相关文章