File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets 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 » Servlets
Bookmark "How to get System Date and time" Watch "How to get System Date and time" New topic

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

Joined: Jan 10, 2002
Posts: 63530

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.

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

Joined: Feb 20, 2001
Posts: 3695

Moving this from Servlets -> Java In General - Beginner
I agree. Here's the link:
subject: How to get System Date and time
It's not a secret anymore!