我正在嘗試獲取 PST 時區一天的開始時間 (00:00:00) 和結束時間 (23:59:59)。我嘗試了以下代碼,但由于某種原因,我只獲得了 UTC 的開始和結束時間。我嘗試更改時區以包含“America/Los_angeles”,但輸出時間戳始終顯示 GMT/UTC 的開始和結束時間。
我的代碼:
val time_zone = ZoneId.of("America/Los_Angeles")
val today_date = LocalDate.now(time_zone).plusDays(0)
val start_time = today_date " " "00:00:00"
val end_time = today_date " " "23:59:59"
val date_format = new SimpleDateFormat("yyyy-MM-dd");
val start_millis = date_format.parse(start_time).getTime();
val end_millis = date_format.parse(end_time).getTime();
start_millis
輸出:
res375: Long = 1656460799000
在紀元轉換器中,1656460799000給了我這個:

我在這里缺少什么嗎?我應該更新任何軟體包等嗎?
uj5u.com熱心網友回復:
只需將此部分添加到您的代碼中:
date_format.setTimeZone(TimeZone.getTimeZone("PST"));
然后它將按您的意愿作業:)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/496967.html
