yehia zakaria
yehia zakaria

Reputation: 81

Convert time stamp to special date format

I'm using java to map timestamp into date with format yyyy/MM/dd HH:mm:ss.

I'm using

Date meetingDate = new Date(Long.parseLong("1369662263618"));            
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println(dateFormat.format(meetingDate.getTime()));
System.out.println(meetingDate);

The result is:

2013/05/27 15:44:23
2013-05-27

I want the date to be in that format like the first result.

Upvotes: 1

Views: 200

Answers (2)

amicngh
amicngh

Reputation: 7899

In order to get the Date in any desired format you will have to use DateFormat .

As per Doc SimpleDateFormat allows you to start by choosing any user-defined patterns for date-time formatting

So you can use same dateFormat to get Text representation of your date

    Date meetingDate = new Date(Long.parseLong("1369662263618"));
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String meetingDateText=dateFormat.format(meetingDate);
    System.out.println(dateFormat.format(meetingDate.getTime()));
    System.out.println(meetingDate);
    System.out.println(meetingDateText);

Upvotes: 0

Bohemian
Bohemian

Reputation: 425198

It's hard to know what you want, but I think you want this:

 System.out.println(dateFormat.format(meetingDate));

Upvotes: 2

Related Questions