Hi nisao-ga,
It is actually fairly simple to obtain the date from within a java
program - all that is required is the java.util.Date and
java.text.DateFormat classes which can be imported as follows:
import java.util.Date;
import java.text.DateFormat;
There is also a tutorial available from Sun that show you how to
customize the output date/time information to suit various locales:
http://java.sun.com/docs/books/tutorial/i18n/format/dateFormat.html
This may be the most useful section for you from that tutorial:
"Formatting dates with the DateFormat class is a two-step process.
First, you create a formatter with the getDateInstance method. Second,
you invoke the format method, which returns a String containing the
formatted date. The following example formats today's date by calling
these two methods:
Date today;
String dateOut;
DateFormat dateFormatter;
dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT,
currentLocale);
today = new Date();
dateOut = dateFormatter.format(today);
System.out.println(dateOut + " " + currentLocale.toString());
The output generated by this code follows. Notice that the formats of
the dates vary with Locale. Since DateFormat is locale-sensitive, it
takes care of the formatting details for each Locale.
9 avr 98 fr_FR
9.4.1998 de_DE
09-Apr-98 en_US
The preceding code example specified the DEFAULT formatting style. The
DEFAULT style is just one of the predefined formatting styles that the
DateFormat class provides, as follows:
DEFAULT
SHORT
MEDIUM
LONG
FULL"
For further information about these classes you may want to visit the
Java API pages:
http://java.sun.com/j2se/1.4/docs/api/java/util/Date.html
http://java.sun.com/j2se/1.4/docs/api/java/text/DateFormat.html
Hope that answers your question :)
answerguru-ga |