jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Date Format (URGENT) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Date Format (URGENT)" Watch "Date Format (URGENT)" New topic

Date Format (URGENT)

Chhaya Dhanani
Ranch Hand

Joined: Apr 11, 2001
Posts: 70
hi all.
i want to dipslay the current date and time in the following format:'02/15/2002 11:41:39 PM'
i know using the java.util.Calender we can do this..
but i tried and cannot get it.
please let me know how i can get this format..
along with the AM/PM also..
a code snippet will be appreciated..
Thanx in advance.. and pls.. reply soon as this is a SOS!!!
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
Try this code,
import java.util.SimpleTimeZone;
import java.util.Date;
import java.text.SimpleDateFormat;
public class datetest{
public static void main(String kk[]){
SimpleTimeZone stz = new SimpleTimeZone(+8*60*60*1000,"Asia/Singapore");
formatter = new SimpleDateFormat("ddMMMyyyy hh:mm:ss a");
Date date = new Date();
String timeStamp = formatter.format(date).toString()+"\n";
System.out.println("Time is "+timeStamp);

Hope this is what u wanted

Chhaya Dhanani
Ranch Hand

Joined: Apr 11, 2001
Posts: 70
yup that is want i wanted!!
Thanks Mahesh..
I agree. Here's the link: http://aspose.com/file-tools
subject: Date Format (URGENT)
It's not a secret anymore!