?
Solved

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

Posted on 2005-03-06
5
Medium Priority
?
1,717 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month8 days, 23 hours left to enroll

765 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