• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Date Format (URGENT)

 
Chhaya Dhanani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
Chhaya
 
Mahesh Mamani
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Try this code,
import java.util.SimpleTimeZone;
import java.util.Date;
import java.text.SimpleDateFormat;
public class datetest{
public static void main(String kk[]){
SimpleDateFormatformatter;
SimpleTimeZone stz = new SimpleTimeZone(+8*60*60*1000,"Asia/Singapore");
SimpleTimeZone.setDefault(stz);
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

Mahesh
 
Chhaya Dhanani
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup that is want i wanted!!
Thanks Mahesh..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic