我已经使用实体管理器执行了查询。它从多个表返回数据。在那种情况下,我会得到对象数组的列表。所以我写了一个循环如下。
for (Object[] row : rows) {
row[0]; //row[0] has the date from database as timestamp.
}
这row[0]
是一个SQL时间戳。
如果我们通过调试进行评估,我将获得Timestamp结果:2020-05-27 18:37:39.0
。
我可以看到cdate
,一个私有变量,其值为2020-05-27T18:37:39.000+0530
。这是公历。我不能使用它,因为它是一个私有变量,并且是type BaseCalendar.Date
。
如果您做某事并将其转换为UTC,我会得到 2020-05-27T13:07:39Z
但是我想要它 2020-05-27T18:37:39.000+0530
使用现代的日期/时间API,如下所示:
import java.time.OffsetDateTime;
import java.time.format.DateTimeFormatter;
public class Main {
public static void main(String args[]) {
// Define the format
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
// Parse the date/time string using the defined format
OffsetDateTime odt = OffsetDateTime.parse("2020-05-27T18:37:39.000+0530", formatter);
// Display
System.out.println(odt);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句