A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
How to print default date in required format
Priya Sri
Ranch Hand
Joined: Mar 30, 2004
Posts: 84
posted
Oct 29, 2004 05:53:00
0
Hi friends,
I was not able to print date in required format....
Iam getting current date using
Date mydate=new Date();
By printing mydate , it is showing date in long format....
How should i get my date in simple format like "29/10/2004"
I tried using
SimpleDateFormat
and
DateFormat
.. But I was not able to get it...
Thanx in advance..
bye
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
I like...
posted
Oct 29, 2004 06:46:00
0
But I was not able to get it...
Well,
SimpleDateFormat
is the simple way of doing this. What went wrong?
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Fisher Daniel
Ranch Hand
Joined: Sep 14, 2001
Posts: 582
posted
Oct 29, 2004 22:38:00
0
Hi,
I usually using DateFormatUtils from org.apache.commons.lang.time to convert date into a specific format.
public static final String DATE_FORMAT = "dd/MM/yyyy"; public static String formatDateToString(Date date) { return (date == null) ? "" : DateFormatUtils.format(date, DATE_FORMAT); }
Hope this help...
Correct me if I am wrong
daniel
Sunil Manheri
Ranch Hand
Joined: Jul 07, 2004
Posts: 32
posted
Oct 29, 2004 23:22:00
0
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MMM/dd"); String dt = dateFormat.format(new Date()); System.out.println(dt);
TechMindViews - Technical Notes
Priya Sri
Ranch Hand
Joined: Mar 30, 2004
Posts: 84
posted
Oct 30, 2004 07:37:00
0
Thank u...
I got it...
I agree. Here's the link:
http://zeroturnaround.com/jrebel
subject: How to print default date in required format
Similar Threads
Date Format in JAVA
error in formatting miliseconds for date objects
integer number too large:
DateFormat
Passing sysdate as parameter to Oracle procedure
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter