简体   繁体   English

Scala/Java joda.time 不以 24 小时格式转换日期

[英]Scala/Java joda.time not converting date in 24 hours format

I am trying to convert a long utc value into "yyyy-MM-dd HH:mm:ss" formatted pattern.我正在尝试将 long utc值转换为"yyyy-MM-dd HH:mm:ss"格式的模式。 I am expecting my data to be converted on 24 hours range scale and in GMT .我希望我的数据在24 hours range scaleGMT转换。 My code passes all the test cases, I push the data into database using the jar that is newly built with this code -我的代码通过了所有测试用例,我使用此代码新建的 jar 将数据推送到数据库 -

dbRecord("order_dt_utc") = if (orderTs.isDefined) Some(new DateTime(orderTs.get, DateTimeZone.UTC).toString("yyyy-MM-dd HH:mm:ss")) else None

and now, when I query my database, I find that the data is still converting on 12 hours range .现在,当我查询我的数据库时,我发现数据仍在转换on 12 hours range The query -查询 -

SELECT order_id, order_dt, order_dt_utc, order_ts_utc, from_unixtime(order_ts_utc/1000) FROM order_items where order_dt >= '2018-08-01' AND order_dt <= '2018-08-02' ORDER BY order_dt_utc LIMIT 1000;

And you can see the the values are not matching in the columns from_unixtime(order_ts_utc/1000) and order_dt_utc -您可以看到from_unixtime(order_ts_utc/1000)order_dt_utc列中的值不匹配 -

在此处输入图像描述

I am not able to figure the reason for this behaviour.我无法弄清楚这种行为的原因。

To convert Time Zone use the function first: CONVERT_TZ (dateobj, oldtz, newtz)要转换时区,首先使用 function: CONVERT_TZ (dateobj, oldtz, newtz)

You can also你也可以

After that use the function:之后使用 function:

date_format(from_unixtime(order_ts_utc), '%Y-%m-%d %H:%i:%s');

to format your time to 00-23 format.将您的时间格式化为00-23格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM