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

Incorrect Timestamp Value - c.getTimeInMills()(时间戳值不正确 - c.getTimeInMills())
本文介绍了时间戳值不正确 - 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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

quot;Char cannot be dereferencedquot; error(“Char 不能被取消引用错误)
Java Switch Statement - Is quot;orquot;/quot;andquot; possible?(Java Switch 语句 - 是“或/“和可能的?)
Java Replace Character At Specific Position Of String?(Java替换字符串特定位置的字符?)
What is the type of a ternary expression with int and char operands?(具有 int 和 char 操作数的三元表达式的类型是什么?)
Read a text file and store every single character occurrence(读取文本文件并存储出现的每个字符)
Why do I need to explicitly cast char primitives on byte and short?(为什么我需要在 byte 和 short 上显式转换 char 原语?)