java - date + time can't convert to milliseccond -
int year = integer.parseint(stransdatetime2.substring(0, 4)); int month = (integer.parseint(stransdatetime2.substring(4, 6)) - 1); int day = integer.parseint(stransdatetime2.substring(6, 8)); int hour = integer.parseint(stransdatetime2.substring(8, 10)); int minute = integer.parseint(stransdatetime2.substring(10, 12)); int second = integer.parseint(stransdatetime2.substring(12)); system.out.println("year=" + year + "| month= " + month + "| day=" + day); dateformat df = new simpledateformat("mm/dd/yyyy"); calendar calconvert = calendar.getinstance(); calconvert.set(year, month, day, hour, minute, second); stransdatetime2 = long.tostring(calconvert.gettimeinmillis() / 1000); system.out.println("debug date: " + stransdatetime2);
my date time year=2017| month= 7| day=28| hour= 17| minute=0, after convert milliseconds become 1501232400. result of date correct, 28 jul 2017, time become 9.00pm. wrong on coding?
thanks
stop learning old broken java.date , move java.time
localdatetime myldt = localdatetime.of(2017, 7, 28, 17, 0); system.out.println(myldt); system.out.println(myldt.atzone(zoneid.systemdefault()).toinstant().toepochmilli());
Comments
Post a Comment