Convert Excel timestamp to java.sql.date -


i extracting timestamp out of excel (2010):

it displayed "10.06.2015 14:24". "internal representation" of excel "42165.6". last 1 outputted excel.

so, now, want parse timestamp java program this:

double input = 42165.6; // long mylong = ??? simpledateformat sdf = new simpledateformat("dd.mm.yyyy hh:mm"); system.out.println(sdf.format(new java.sql.date(mylong))); 

how can in line 2?!

many help!!!

kind regards

excel stores dates number of days since january 1900. makes awkward convert java date (milliseconds since 1 jan 1970). if cannot export in readable format, you'll need create java calendar, set 1 jan 1900, , add number of days.

here is:

    double exceldate = 42165.6;     int days = (int) exceldate;  //number of days     int seconds = (int) ((exceldate-days) * 86400);  //number of seconds in .6 days      //create calendar set 01-jan-1900     calendar cal = calendar.getinstance();     cal.set(calendar.year, 1900);     cal.set(calendar.month, 0);     cal.set(calendar.day_of_month, 1);      //add days , seconds required date/time     cal.add(calendar.date, days-1);     cal.add(calendar.second, seconds);      //cal.gettime() returns java.util.date, print out...     system.out.println(cal.gettime()); 

note java.sql.date can created java.util.date follows:

java.util.date utildate = .... java.sql.date sqldate = new java.sql.date(utildate.gettime()); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -