Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
How to format datetime?
Siegfried Heintze
Ranch Hand
Posts: 428
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I'm doing following presently when fetching date from
JDBC
:
Date date = results.getDate(column); final DateFormat df = DateFormat.getDateInstance(DateFormat.LONG); final Format formatter = new SimpleDateFormat("hh:mm:ss"); data = "'" + df.format(date)+ " " + formatter.format(date) + "'";
Please tell me there is a better way! How can I format my date with a single formatter?
Thanks,
Siegfried
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can just use SimpleDateFormat. Why do you think you need separate formatters for the date and time parts?
Date date = results.getDate(column); DateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); System.out.println("Formatted date: " + df.format(date));
See the API documentation of java.text.SimpleDateFormat for info on the format specification
string
.
Jesper's Blog
-
Pluralsight Author Page
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
using java.util.Logging to generate a txt log file
NumberFormatException while inserting data into database
problem with selecting data between two dates in sqlserver
Date format... please help
How to compare 2 Dates in String Format
More...