Link to home
Start Free TrialLog in
Avatar of richardsimnett
richardsimnett

asked on

getting todays date as mm/dd/yyyy hh:mm:ss

Hello,
Can anyone tell me how to get a string which is todays date and time in the format of mm/dd/yyyy hh:mm:ss?

Worth 500 points.

Thanks,
Rick
Avatar of ldbkutty
ldbkutty
Flag of India image

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String today = sdf.format(new Date());
System.out.println(today);
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
String today = sdf.format(new Date());

// HH => 0 to 23 ; hh => 1 to 12 ; a => AM or PM

http://javaalmanac.com/egs/java.text/FormatDate.html
http://javaalmanac.com/egs/java.text/FormatTime.html
Avatar of richardsimnett
richardsimnett

ASKER

lbdkutty,
what package do I need to import for that code to complile properly?

Thanks,
Rick
ASKER CERTIFIED SOLUTION
Avatar of ldbkutty
ldbkutty
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Works great.

Thanks,
Rick