I am experimenting with DateFormat, and I ran into a problem when I create a date, saving it as a string, and then parse it back to a date and somehow ending with the same date, but on a different day of the week.
import java.text.*; import java.util.*; public class Dates { public static void main (String [] args) { Date d1 = new Date(1000000000000000L); System.out.println("d1 = " + d1.toString()); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); String s = df.format(d1); System.out.println(s); try { Date d2= df.parse(s); System.out.println( "Parsed Date = " + d2.toString()); } catch (ParseException e) { System.out.println("Parse Exception"); } } }
I get the output:
d1 = Fri Sep 27 02:46:40 BST 33658 27/09/58 Parsed Date = Sat Sep 27 00:00:00 BST 1958
If the number of minutes in milliseconds is less than when the date is parsed, this will work as I would expect if the parsing day coincided with the start day.
Not sure what is going on, can anyone explain this?
source share