my dog learned polymorphism*
The moose likes Beginning Java and the fly likes How to get System Date and time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to get System Date and time" Watch "How to get System Date and time" New topic
Author

How to get System Date and time

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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61227
    
  66

You can get the current date/time by simply creating a java.util.Date instance with the default constructor. If you need to use a java.sql.Date for whatever reason, you need to initialize it as new java.sql.Date( System.currentTimeMillis() ).
You can format the date as you like using a java.text.DateFormat instance.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Moving this from Servlets -> Java In General - Beginner
 
wood burning stoves
 
subject: How to get System Date and time