I came across a weird issue, during the cloud migration where the MS SQL Server on cloud made use of time zone UTC. Some where in the code, I had a check where the update time stamp which is based on CDT is compared against the DB server time.
This is how I mitigated that issue,
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat
.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSSS Z");
resultSetData = dbConfig.executeQuery("SELECT SYSDATETIMEOFFSET() AS CurrentDateTime");
For some reason, the time returned by the above query has 7 precision for milli seconds.
if (resultSetData != null && resultSetData .next()) {
String currentDateTimeStr = resultSetData .getString("CurrentDateTime");
DateTime datetime = DATE_TIME_FORMATTER.parseDateTime(currentDateTimeStr);
currentDBTimestamp = datetime.getMillis();
}
This is how I mitigated that issue,
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat
.forPattern("yyyy-MM-dd HH:mm:ss.SSSSSSS Z");
resultSetData = dbConfig.executeQuery("SELECT SYSDATETIMEOFFSET() AS CurrentDateTime");
For some reason, the time returned by the above query has 7 precision for milli seconds.
if (resultSetData != null && resultSetData .next()) {
String currentDateTimeStr = resultSetData .getString("CurrentDateTime");
DateTime datetime = DATE_TIME_FORMATTER.parseDateTime(currentDateTimeStr);
currentDBTimestamp = datetime.getMillis();
}
No comments:
Post a Comment