Now, let’s explore another exciting approach to get the timestamp using the OffsetDateTime class. Further, we need to convert it to an Instant type and access the toEpochMilli() method for getting the timestamp value. It’s imperative to note that the LocalDateTime object lacks any information about the zone, so we must associate it with the local time zone. Val currentTimestamp: Long = zonedDateTime.toInstant().toEpochMilli() ![]() The time shown here is independent from your computer or phone. Val zonedDateTime: = localDateTime.atZone(("Asia/Kolkata")) This internet clock displays the time for various cities around the world. Moving on, let’s also learn how we can get the current timestamp from an instance of the LocalDateTime class: val localDateTime: = () ![]() Other names: Universal Time Coordinated / Universal Coordinated Time. In this case, we created the zoneId object using the preferred time zone of “ America/New_York” and supplied the zoneId instance to the now() method. UTC / GMT is the basis for local times worldwide. We must note that we’re using the system’s default zone to initialize the currentZonedDateTime variable.įurthermore, we could also provide a custom ZoneId value to the now() method: val zoneId: = ("America/New_York") Online Clockface Aesthetic Clockfaces Live Time Display Great for remote working/learning Huge range of clocks. Online Clock This is our FULLSCREEN Clock with a smooth running seconds hand. Val currentTimestamp: Long = currentZonedDateTime.toInstant().toEpochMilli() ![]() Next, let’s create an instance of the ZonedDateTime class and use the toEpochMilli() method to get the current timestamp: val zoneId: = () We used the now() method to query the current date and time from the system clock and then used the toEpochMilli() method to get the current timestamp. Val currentTimeStamp: Long = currentInstant.toEpochMilli()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |