jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to get system date and format it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how to get system date and format it" Watch "how to get system date and format it" New topic

how to get system date and format it

Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
I am trying to save a xml file. I want to retrieve
the system date and name the file as systemdate
stamp like mmddyyhrminutes(in this format).
Do you know how to retrieve system date and
format it in that way

Bhasker Reddy
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
Look at the java.util.Calendar class, as well as java.text.DateFormat.
These classes will give you the tools you need.


SCJP 1.4
Rajinder Yadav
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
One thing to keep in mind, if you are writing the software program that's going to be used by others people then always remember to format the date and time to the local format.
I know that in Canada the date format is mm/dd/yy, and in the US I believe is dd/mm/yy or is it the other was around? Oh well that's what the local format utility is for
Take a look at these classes

<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
padma Doddapaneni

Joined: Jan 21, 2002
Posts: 5
import java.util.*;
import java.text.*;
import java.text.SimpleDateFormat;
public class Todaysdate{
public static String getDate(){
Date today = new Date();
String mystring =
DateFormat.geInstance ().format(today);
String date = mystring.substring(0,8);
return date;
// you can call this static method todaydate=Todaysdate.getDate() or you can change the format you want.
If I am wrong please correc me
I agree. Here's the link: http://aspose.com/file-tools
subject: how to get system date and format it
It's not a secret anymore!