Date format

I need to display Month in 2 digits. eg. 01 for Jan, 02 for Feb, 03 March and so on and date also in 2 digits - 01, 02, 03, 04...09.

Also I have to extract the last 6 digits for milliseconds

long S = System.currentTimeMillis(); - This returns 13 digits.

I tried to use length() with an int variable. I get the following error

The primitive type int of <variable> does not have a field length

Please help. Thanks

[457 byte] By [JSP_Helpa] at [2007-10-2 16:52:53]
# 1

long is a primitive element which does not have any properties

> long S = System.currentTimeMillis(); - This returns 13 digits.

This returns a long if you convert it to a String it may be displayed with 13 digits.

> long S = System.currentTimeMillis(); - This returns 13 digits.

> Also I have to extract the last 6 digits for milliseconds

? That are milliseconds

DateFormat format = new SimpleDateFormat("SSS");

// returns the milliseconds of the current Date

// (new Date()).getTime() returns the same as System.currentTimeMillis()

String currentMillis = format(new Date());

// returns the current month in two digit format

DateFormat month = new SimpleDateFormat("MM") ;

See http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

for details about the SimpleDateFormat patterns.

andi

andiha at 2007-7-13 18:04:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Sorry for not being clear with milliseconds.I need to extract the last 6 digits from milliseconds. If I convert into a string, what is the function to get the last 6 digits.btw, I was able to add 0 to the month if less than 10.Thanks for your reply.
JSP_Helpa at 2007-7-13 18:04:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

System.currentTimeMillis() returns a UTC time - number of milliseconds since 1 Jan 1970.

Taking the last 6 digits of that doesn't really mean anything.

Number of milliseconds in a day is normally 60 * 60 * 1000 = 3600000.

That is seven digits long.

What is it that you think the last 6 digits mean that you need to get it?

long S = System.currentTimeMillis();

String last6Digits = "" + S;

last6Digits = last6Digits.substring( last6Digits.length()-6, last6Digits.length();

int ssss = Integer.parseInt(last6Digits);

But I still don't know what it means.

evnafetsa at 2007-7-13 18:04:51 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...