ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ZonedDateTime获取一段时间间隔的时间列表

2020-03-02 17:36:03  阅读:431  来源: 互联网

标签:02 间隔 28T00 00.000 列表 2020 newDate ZonedDateTime


    public static ArrayList<String> getDateIntervalList(ZonedDateTime start, ZonedDateTime end) {
        ArrayList<String> utcDateList = new ArrayList<>();
        //输出的时间样式这里是UTC时间
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        //初始化新时间,当新时间在结束时间之前时,将新时间放入列表,然后新时间+1分钟,这里plusDays、plusMonths等
        for (ZonedDateTime newDate = start.withZoneSameInstant(ZoneId.of("Asia/Shanghai"));
             newDate.isBefore(end); newDate = newDate.plusMinutes(1) ) {
            utcDateList.add(newDate.format(formatter));
        }
        utcDateList.add(end.format(formatter));
        return utcDateList;
    }

    public static void main(String[] args){
           ZonedDateTime start = ZonedDateTime.of(2020, 2, 28,
                    0, 0, 0, 0, beijing);
            ZonedDateTime end = ZonedDateTime.of(2020, 2, 28,
                    1, 0, 0, 0, beijing);
            ArrayList<String> dateList =  getDateIntervalList(start, end);
            System.out.println(dateList);
                    
}
[2020-02-28T00:00:00.000Z, 2020-02-28T00:01:00.000Z, 2020-02-28T00:02:00.000Z, 2020-02-28T00:03:00.000Z, 2020-02-28T00:04:00.000Z, 2020-02-28T00:05:00.000Z, 2020-02-28T00:06:00.000Z, 2020-02-28T00:07:00.000Z, 2020-02-28T00:08:00.000Z, 2020-02-28T00:09:00.000Z, 2020-02-28T00:10:00.000Z, 2020-02-28T00:11:00.000Z, 2020-02-28T00:12:00.000Z, 2020-02-28T00:13:00.000Z, 2020-02-28T00:14:00.000Z, 2020-02-28T00:15:00.000Z, 2020-02-28T00:16:00.000Z, 2020-02-28T00:17:00.000Z, 2020-02-28T00:18:00.000Z, 2020-02-28T00:19:00.000Z, 2020-02-28T00:20:00.000Z, 2020-02-28T00:21:00.000Z, 2020-02-28T00:22:00.000Z, 2020-02-28T00:23:00.000Z, 2020-02-28T00:24:00.000Z, 2020-02-28T00:25:00.000Z, 2020-02-28T00:26:00.000Z, 2020-02-28T00:27:00.000Z, 2020-02-28T00:28:00.000Z, 2020-02-28T00:29:00.000Z, 2020-02-28T00:30:00.000Z, 2020-02-28T00:31:00.000Z, 2020-02-28T00:32:00.000Z, 2020-02-28T00:33:00.000Z, 2020-02-28T00:34:00.000Z, 2020-02-28T00:35:00.000Z, 2020-02-28T00:36:00.000Z, 2020-02-28T00:37:00.000Z, 2020-02-28T00:38:00.000Z, 2020-02-28T00:39:00.000Z, 2020-02-28T00:40:00.000Z, 2020-02-28T00:41:00.000Z, 2020-02-28T00:42:00.000Z, 2020-02-28T00:43:00.000Z, 2020-02-28T00:44:00.000Z, 2020-02-28T00:45:00.000Z, 2020-02-28T00:46:00.000Z, 2020-02-28T00:47:00.000Z, 2020-02-28T00:48:00.000Z, 2020-02-28T00:49:00.000Z, 2020-02-28T00:50:00.000Z, 2020-02-28T00:51:00.000Z, 2020-02-28T00:52:00.000Z, 2020-02-28T00:53:00.000Z, 2020-02-28T00:54:00.000Z, 2020-02-28T00:55:00.000Z, 2020-02-28T00:56:00.000Z, 2020-02-28T00:57:00.000Z, 2020-02-28T00:58:00.000Z, 2020-02-28T00:59:00.000Z, 2020-02-28T01:00:00.000Z]

yhf597869822 发布了3 篇原创文章 · 获赞 0 · 访问量 159 私信 关注

标签:02,间隔,28T00,00.000,列表,2020,newDate,ZonedDateTime
来源: https://blog.csdn.net/yhf597869822/article/details/104615669

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有