+ 1
TimeZone and MilliSeconds
Hi, I'm able to get the current time by using LocalDateTime and I'm also able to get milliseconds using long milliSeconds = Timestamp.valueOf(today).getTime(); The problem is the current time I'm getting is not in my time zone. So how will I able to get my desired time zone? You can check my code. https://code.sololearn.com/c7zueeCtLf2d/?ref=app https://code.sololearn.com/c7zueeCtLf2d/?ref=app
3 odpowiedzi
+ 2
bear in mind thar Timestamp can’t handle ZonedDateTime. You have to remove the zone information first:
ZoneId timeZone = ZoneId.of("Africa/Johannesburg");
ZonedDateTime today = ZonedDateTime.now(timeZone);
LocalDateTime withoutTimezone = today.toLocalDateTime();
long milliSeconds = Timestamp.valueOf(withoutTimezone).getTime();
+ 2
try :
ZoneId z = ZoneId.systemDefault() ZonedDateTime zdt = ZonedDateTime.now( z ) ;
+ 1
Thanks, I figured out the answer.