Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to get system date and format it

 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the java.util.Calendar class, as well as java.text.DateFormat.
These classes will give you the tools you need.

Rob
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
java.util.Date
java.text.DateFormat
java.text.DateFormatSymbols
java.text.Format
 
padma Doddapaneni
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Padma
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic