小编Gui*_*ves的帖子

ZonedDateTime.ofInstant 不显示秒

我试图使用 ZonedDateTime.ofInstant 给出特定的日期时间来获取时间,但是我注意到在某些情况下给出的结果不包含秒。代表我正在处理的情况的代码示例

import java.time.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
  
        
        // create a long variable for milliseconds
        //this is the same as "2022-01-31T00:00:00.00Z"
        long milliseconds1  = 1643587200000L;
        long milliseconds2  = 1643587201000L;
            

        // get Instant using ofEpochMilli() method
        Instant instant1
            = Instant.ofEpochMilli(milliseconds1); 
        // create Instant object
        Instant instant2
            = Instant.ofEpochMilli(milliseconds2);
  
        // create a ZonID
        ZoneId zone = ZoneId.of("Europe/Lisbon");
  
        // apply ofInstant method
        // of ZonedDateTime class
        ZonedDateTime zt1 = ZonedDateTime
                               .ofInstant(instant1, zone);
        ZonedDateTime zt2 = ZonedDateTime …
Run Code Online (Sandbox Code Playgroud)

java datetime

1
推荐指数
1
解决办法
692
查看次数

标签 统计

datetime ×1

java ×1