java - java format timestamps with "Z" instead of "+"
问题描述
Using java I try to format the current date with the timezone using SimpleDateFormat
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss:SSSZ");
sdf.format(new Date());
This give me as results :
2021-04-28T13:45:52:308+0300
I want to get the timezone format with the "Z" instead of "+"
wanted results : "2021-04-28T13:45:52:308Z03:00"
I writed the date output in a file log that will be parsed by telegraf plugin writed in Go language that expect date with time zone with the following format : json_time_format = "2006-01-02T15:04:05Z07:00"
Is there a pattern allows that ?
解决方案
Z is for "Zulu time" or zero hour offset, i.e. UTC +0:00
It's not correct to use it if you're not in that timezone. How would you know whether you're before or after the meridian if you replace it with Z
? Given Z03:00
do you parse it as +03:00
or -03:00
?
推荐阅读
- c# - Entity Framework .Net 核心不添加存储过程类
- flutter - Flutter 中的后台服务每 10 秒运行一次
- firebase - Firebase HTTP 云函数 - 500 服务器错误,请重试
- javascript - 如何在Google表格中的一列中获取数组的总和
- python - 如何使用 try 函数处理 python 中的特定整数异常。如何处理多个除了尝试功能
- python - 如何使用 python 连接到 Nonstop 上的 sql/mp 或 sql/mx 数据库。
- ios - 在 swift 5 中更改 UITableView 中的单元格大小
- c++ - 了解C++程序的开发周期
- google-apps-script - 以编程方式测试 Google 表格单元格是否在命名范围内
- linux - imagemagic 的转换命令在我的系统上似乎无法正常工作