[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

time stamp in Excel

My servlet queries a table to retrieve information including a column with timestamps. I then display the information in an Excel spreadsheet but it displays only the time. I can format the column in Excel to display the date and time in the column but was wondering if there was a way to do this through the code. Thanks!
0
g125047
Asked:
g125047
1 Solution
 
udaykumar22Commented:
hi g125047,

Use the SimpleDateFormat class in java.text package.

===========================================================

When you retrieve your resultset :-

SimpleDateFormat SDF
     = new SimpleDateFormat ("yyyy.MM.dd hh:mm:ss");
 Date dateTime = rsltSet.getTimestamp();
 String dateString = SDF.format(dateTime);

===========================================================

This would give you the date and time in string format and you can then use this for storing into the excell sheet.

===========================================================

Regards,
Uday.

0
 
g125047Author Commented:
Thanks so much. Just a note that I had to use the Timestamp class instead of the Date class for the code to work.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now