Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

java - Incorrect Timestamp Value - c.getTimeInMills()

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();

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

Edit: 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...