Group long UTC by day

Is there any reasonable way to group long UTC dates by day?

I would change them to 86400, but it does not take a second per second.

Does anyone have any other ideas, I use java, so I can parse them into Date Objects, but I'm a bit concerned about the overhead of performance on using a date class.

There is also a more efficient way than comparing the parts of the month and day of the year of a Date object?

+3
source share
3 answers

? API , - Joda ( API- /) , . API- Java "" - 60 61 " ", (. ). , , . , , - .

Date ( DateTime Joda), , - . , . , -, . , , , :)

java.util.Date . :

Date (UTC), , , Java. , 1 = 24 × 60 × 60 = 86400 . UTC, , -, " ". , 31 30 . , 1995 61 , . , .

Java , .

+3

86400, .

, . API Date , , Unix, . 59- , , 1 ( ).

, , Date.getTime() IS, 86400 . , , ( 1972 23-24, , ).

...

+3

TL;DR

Instant.ofEpochSecond( 1_493_367_302L )            // Convert a count of whole seconds from epoch of 1970 into a date-time value in UTC.
       .atZone( ZoneId.of( "Pacific/Auckland" ) )  // Adjust into the time zone as a context for determining a date.
       .toLocalDate()                              // Extract a date-only value by which we can sort/collect/organize our date-time values.

java.util.Date UTC. , , , UTC. , .

, .

java.time

java.util.Date , , java.time.

, , . .

1970-01-01T00:00:00, Instant.

Instant instant = Instant.ofEpochSecond( 1_493_367_302L ) ;

instant.toString(): 2017-04-28T08: 15: 02Z

, . .

continent/region, America/Montreal, Africa/Casablanca Pacific/Auckland. 3-4 , EST IST, , (!).

ZoneId z = ZoneId.of( "America/Montreal" ); 
ZonedDateTime zdt = instant.atZone( z );

zdt.toString(): 2017-04-28T01:15: 02-07: 00 [America/Los_Angeles]

ZonedDateDate . LocalDate. LocalDate .

LocalDate ld = zdt.toLocalDate();

ld.toString(): 2017-04-28

, Map LocalDate List Set ZonedDateTime . Streams .


java.time

java.time Java 8 . legacy , java.util.Date, Calendar SimpleDateFormat.

Joda-Time, , java.time.

, . Oracle. Qaru . JSR 310.

java.time?

The ThreeTen-Extra project extends java.time with additional classes. This project is proof of possible future additions to java.time. Here you can find useful classes, such as Interval, YearWeek, YearQuarterand longer .

0
source

Source: https://habr.com/ru/post/1705258/