I've noted very strange behaviour in some Apex code I'm running. If I use the Date.ValueOf() function on a datetime. If I then print out the DateTime afterwards the hour/minutes of it have changed to 03:00.
The following code is an example which causes this.
DateTime test1 = System.Now();
System.debug('Hello Test1 BeforeDateValueOf ' + test1);
Date test1Date = Date.ValueOf(test1);
System.debug('Hello Test1 ' + test1);
Prints out the following:
16:19:03:002 USER_DEBUG [2]|DEBUG|Hello Test1 BeforeDateValueOf 2018-07-20 15:19:03 16:19:03:064 USER_DEBUG [4]|DEBUG|Hello Test1 2018-07-20 03:00:00
Why is the time of test1
variable has changed? Surely test1Date
is treated separately?
test1.date()
?