Skip to main content
deleted 2 characters in body
Source Link
BenjyTec
  • 12.6k
  • 4
  • 27
  • 56

In case of LocalDate, you can use the toEpochDay()toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDaystoEpochDay()); 

Documentation can be found here.

In case of LocalDateTime, you can use the toEpochSecond()toEpochSecond() method. It returns the number of seconds since 01/01/1970. That number then can be converted to milliseconds, too:

long dateTimeInMillis = TimeUnit.SECONDS.toMillis(myLocalDateTime.toEpochSecondstoEpochSecond()); 

Documentation for that is here.

In case of LocalDate, you can use the toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDays()); 

Documentation can be found here.

In case of LocalDateTime, you can use the toEpochSecond() method. It returns the number of seconds since 01/01/1970. That number then can be converted to milliseconds, too:

long dateTimeInMillis = TimeUnit.SECONDS.toMillis(myLocalDateTime.toEpochSeconds()); 

Documentation for that is here.

In case of LocalDate, you can use the toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDay()); 

In case of LocalDateTime, you can use the toEpochSecond() method. It returns the number of seconds since 01/01/1970. That number then can be converted to milliseconds, too:

long dateTimeInMillis = TimeUnit.SECONDS.toMillis(myLocalDateTime.toEpochSecond()); 
deleted 119 characters in body
Source Link
BenjyTec
  • 12.6k
  • 4
  • 27
  • 56

There are some methods available that no one has mentioned here. But I don't see a reason why they should not work.

In case of LocalDate, you can use the toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDays()); 

Documentation can be found here.

In case of LocalDateTime, you can use the toEpochSecond() method. It returns the number of seconds since 01/01/1970. That number then can be converted to milliseconds, too:

long dateTimeInMillis = TimeUnit.SECONDS.toMillis(myLocalDateTime.toEpochSeconds()); 

Documentation for that is here.

There are some methods available that no one has mentioned here. But I don't see a reason why they should not work.

In case of LocalDate, you can use the toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDays()); 

Documentation can be found here.

In case of LocalDateTime, you can use the toEpochSecond() method. It returns the number of seconds since 01/01/1970. That number then can be converted to milliseconds, too:

long dateTimeInMillis = TimeUnit.SECONDS.toMillis(myLocalDateTime.toEpochSeconds()); 

Documentation for that is here.

In case of LocalDate, you can use the toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDays()); 

Documentation can be found here.

In case of LocalDateTime, you can use the toEpochSecond() method. It returns the number of seconds since 01/01/1970. That number then can be converted to milliseconds, too:

long dateTimeInMillis = TimeUnit.SECONDS.toMillis(myLocalDateTime.toEpochSeconds()); 

Documentation for that is here.

added 442 characters in body
Source Link
BenjyTec
  • 12.6k
  • 4
  • 27
  • 56

There are some methods available that no one has mentioned here. But I don't see a reason why they should not work.

In case of LocalDate, which you are referring to in the description of your question, you can use the toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDays()); 

Documentation can be found here.

In case of LocalDateTime, you can use the toEpochSecond() method. It returns the number of seconds since 01/01/1970. That number then can be converted to milliseconds, too:

long dateTimeInMillis = TimeUnit.SECONDS.toMillis(myLocalDateTime.toEpochSeconds()); 

Documentation for that is here.

In case of LocalDate, which you are referring to in the description of your question, you can use the toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDays()); 

Documentation can be found here.

There are some methods available that no one has mentioned here. But I don't see a reason why they should not work.

In case of LocalDate, you can use the toEpochDay() method. It returns the number of days since 01/01/1970. That number then can be easily converted to milliseconds:

long dateInMillis = TimeUnit.DAYS.toMillis(myLocalDate.toEpochDays()); 

Documentation can be found here.

In case of LocalDateTime, you can use the toEpochSecond() method. It returns the number of seconds since 01/01/1970. That number then can be converted to milliseconds, too:

long dateTimeInMillis = TimeUnit.SECONDS.toMillis(myLocalDateTime.toEpochSeconds()); 

Documentation for that is here.

Source Link
BenjyTec
  • 12.6k
  • 4
  • 27
  • 56
Loading