时间戳值不正确

编程入门 行业动态 更新时间:2024-10-10 23:18:07
本文介绍了时间戳值不正确 - 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.

更多推荐

时间戳值不正确

本文发布于:2023-11-27 11:22:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637852.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不正确   时间

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!