我希望在 spark 中將日期轉換為減去 1 12:00 AM(紀元時間)
val dateInformat=DateTimeFormatter.ofPattern("MM-dd-yyyy")
val batchpartitiondate= LocalDate.parse("10-14-2022",dateInformat)
batchpartitiondate: javatimelocalDate=2022-10-14
batchpartitiondate should be converted to epochtime(1665619200)
例如日期:
火花提交引數中的 InputDate 是 12-15-2022
我需要輸出為紀元時間(1665705600),即格林威治標準時間:星期五,十月 14,12:00:00AM
如果我將輸入作為 2022 年 12 月 14 日,它應該將輸出作為紀元時間 (1665619200) 即在 GMT:星期四,十月 13,12:00:00AM
uj5u.com熱心網友回復:
這是否實作了您想要做的事情?
val dateInFormat = DateTimeFormatter.ofPattern("MM-dd-yyyy")
val batchPartitionDate = LocalDate.parse("10-14-2022", dateInformat)
val alteredDateTime = batchPartitionDate.minusDays(1).atStartOfDay()
// current zone
{
val zone = ZoneId.systemDefault()
val instant = alteredDateTime.atZone(zone).toInstant
val epochMillis = instant.toEpochMilli
}
// UTC
// Or you can specify the appropriate timezone insteasd of UTC
{
val zone = ZoneOffset.UTC
val instant = alteredDateTime.toInstant(zone)
val epochMillis = instant.toEpochMilli
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/515719.html
