Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the alternative classes for localTime and localDate in Android? [duplicate]

I want to use long value I got from android API that return me dates as longs, represented as milliseconds since Epoch.

I need to use methods like isBefore() plusDays() isAfter()

Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI,
                    new String[]{"number", "type", "date", "duration", "name"},
                    null, null, strOrder);

In java I can use LocalDate and LocalTime classes to handle this, unfortunately these classes don't exist on android so what classes available on android similar to localdate and localtime?

like image 301
user3341564 Avatar asked May 14 '16 10:05

user3341564


People also ask

What is the difference between LocalDate and LocalDateTime?

LocalDate – represents a date (year, month, day) LocalDateTime – same as LocalDate, but includes time with nanosecond precision.

What is the default format of LocalTime in Java 8?

LocalTime is an immutable class whose instance represents a time in the human readable format. It's default format is hh:mm:ss. zzz.

Which of the following method of LocalDate can be used to get new LocalDate instance with only the day of the month altered?

The withDayOfMonth() method of LocalDate class in Java returns a copy of this LocalDate with the day-of-month altered.

Which method of LocalDateTime can be used to get the current date and time?

now() now() method of a LocalDateTime class used to obtain the current date-time from the system clock in the default time-zone. This method will return LocalDateTime based on system clock with default time-zone to obtain the current date-time.


1 Answers

https://github.com/dlew/joda-time-android

This is the library that most use for time in Android. A bit heavy on size, but if that's not an issue then it's way better than using utils Android gives you

like image 89
paul_hundal Avatar answered Sep 18 '22 22:09

paul_hundal