Get the start time of the first 30 days in Java

I tried to get the current date and time for the first 30 days But it's nothing else

new Date(System.currentTimeMillis() - 30 * 24 * 60 * 60 * 1000)

This is regression

Tue Jul 21 04:41:20 IST 2015

Is there anything wrong

Solution

Never, never done anything like system Currenttimemillis () – things like 30 * 24 * 60 * 60 * 100 have many rules and time manipulation, which never works

Time API for Java 8

LocalDateTime ldt = LocalDateTime.Now().minusDays(30);

Which output 2015-06-01t16:15:54.868

JodaTime

LocalDateTime ldt = new LocalDateTime();
ldt = ldt.minusDays(30);

Which output 2015-06-01t16:18:22.489

calendar

If you're really desperate

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE,-30);
Date date = cal.getTime();

The output is mon Jun 01 16:19:45 2015

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>