Hello
how is it possible to convert a date in long format since 1 january 1970
to YYYY/MM/DD HH:MM:SS.
Thank in advance,
Nico
Printable View
Hello
how is it possible to convert a date in long format since 1 january 1970
to YYYY/MM/DD HH:MM:SS.
Thank in advance,
Nico
One of the constructors for the java.util.Date class is defined as:
Date(long date)
Allocates a Date object and initializes it to represent the
specified number of milliseconds since the standard base time known as "the
epoch", namely January 1, 1970, 00:00:00 GMT.
(copied from the Java documentation). That sounds like it should work for
the first half of your question. If you want to display a date in a
particular format, you might start by looking at the documentation for class
java.text.SimpleDateFormat.
Nicolas <nsylla@quallaby.fr> wrote in message
news:3948fe86$1@news.devx.com...
>
> Hello
> how is it possible to convert a date in long format since 1 january 1970
> to YYYY/MM/DD HH:MM:SS.
>
>
> Thank in advance,
>
> Nico
You can use SimpleDateFormat class which is in java.text package.
You can convert any format of date to what ever the way you want.
Eg.
import java.text.*;
import java.util.*;
public class Test
{
public static void main(String args[])
SimpleDateFormat fmt = new SimpleDateFormat("yyyy/MM/DD HH:mm:ss");
String date = fmt.format(Calendar.getInstance().getTime());
System.out.println(date);
}
}
"Nicolas" <nsylla@quallaby.fr> wrote:
>
>Hello
>how is it possible to convert a date in long format since 1 january 1970
>to YYYY/MM/DD HH:MM:SS.
>
>
>Thank in advance,
>
>Nico