date format - Java DateFormat issue on Mac vs Windows -
i using code below on mac osx 10.10.2 , it's behaving strangely.
import java.text.dateformat; import java.text.simpledateformat; import java.util.date; public class stringtodate { public static void main(string[] args) throws exception { string dateinstring = "23/oct/2015"; dateformat formatter = new simpledateformat("dd/mmm/yyyy"); date date = formatter.parse(dateinstring); system.out.println(date); } }
output on mac:
sun dec 28 00:00:00 cst 2014
output on windows: fri oct 23 00:00:00 cdt 2015
why mac output wrong?
y
week year. use y
year.
dateformat formatter = new simpledateformat("dd/mmm/yyyy");
also, make sure dateformat's locale right one.
edit:
a date has millisecond precision, if want nanosecond precision, shouldn't use date , simpledateformat.
s milliseconds. since tell simpledateformat last part of string milliseconds, parses that: 545000000 milliseconds (i.e. bit more 6 days, explains difference between input , output).
to accurate result, millisecond, remove last 6 characters of string, , use pattern "dd-mmm-yyyy-hh.mm.ss.sss".
Comments
Post a Comment