Solved

How to get the date and time in java?

Posted on 2011-03-16
3
241 Views
Last Modified: 2012-06-21
Hi,
How can I get the date and time in java in this format?

2011-01-28 10:49 EST

Thanks,
0
Comment
Question by:Tolgar
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 250 total points
ID: 35151963
Try
String s = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm Z").format(new java.util.Date());

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35152010
Actually, make that
String s = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm z").format(new java.util.Date());
or
String s = String.format("%tF %<tR %<tZ", new java.util.Date());

Open in new window

0
 
LVL 92

Expert Comment

by:objects
ID: 35152150
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

Suggested Solutions

Title # Comments Views Activity
Running JavaFX on JDeveloper 12C 1 78
ejb example issues 3 53
JAVA API design with micro service cloud in mind 1 81
wild fly 8 startup error 2 42
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

733 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