?
Solved

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

Posted on 2005-03-06
5
Medium Priority
?
1,718 Views
Last Modified: 2008-03-17
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
0
Comment
Question by:richardsimnett
  • 3
  • 2
5 Comments
 
LVL 32

Expert Comment

by:ldbkutty
ID: 13472762
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String today = sdf.format(new Date());
System.out.println(today);
0
 
LVL 32

Expert Comment

by:ldbkutty
ID: 13472772
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
0
 

Author Comment

by:richardsimnett
ID: 13472789
lbdkutty,
what package do I need to import for that code to complile properly?

Thanks,
Rick
0
 
LVL 32

Accepted Solution

by:
ldbkutty earned 2000 total points
ID: 13472790
import java.util.*;
import java.text.*;
0
 

Author Comment

by:richardsimnett
ID: 13472821
Works great.

Thanks,
Rick
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month3 days, 7 hours left to enroll

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question