[英]How to print date string with ISO8601 format?
Please help me to print my date in below format Example: 2020-08-05T16:17:10,777
I tried with below date converter but it is not giving the output that I want.请帮助我以以下格式打印我的日期示例:
2020-08-05T16:17:10,777
我尝试使用以下日期转换器,但它没有给出我想要的 output。
SimpleDateFormat sdf;
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
String text = sdf.format(requestTime);
loggdata.append(REQUEST_TIME + requestDate);
I got date printed like "2020-08-20T06:26:09.003763Z".我的日期打印为“2020-08-20T06:26:09.003763Z”。 Date is in UTC tomezone and format is different.
日期在 UTC 区域,格式不同。
I can see many question and answers here in stackoverflow.我可以在 stackoverflow 中看到很多问题和答案。 But here in my case I need exactly this format 2020-08-05T16:17:10,777 see the last portion ",777".
但在我的情况下,我需要这种格式 2020-08-05T16:17:10,777 请参阅最后一部分“,777”。 Also I need to display the time in local timezone
我还需要在本地时区显示时间
Found a solution for the same.找到了相同的解决方案。 I have used "LocalDateTime" for the same.
我也使用了“LocalDateTime”。
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss,SSS");
String dateInString= now.format(formatter);
It displayed date like this "2020-08-20T21:18:56,321"它显示这样的日期“2020-08-20T21:18:56,321”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.