Fix bug in hive with 24 hour timestamp.

This is a backport of:
https://issues.apache.org/jira/browse/HIVE-3850