user1742919
user1742919

Reputation: 401

How to get time with GMT like 2016-02-28/20:31 GMT

I want time with GMT string too.

But Im not able to get it.

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd/hh-mm");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Date date = new Date();
System.out.println("date "+dateFormat.format(date));

But Im getting like this 2015-12-28/11-53 without GMT at the end

Upvotes: 0

Views: 62

Answers (1)

Azat Nugusbayev
Azat Nugusbayev

Reputation: 1421

Use

 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd/hh-mm z");
 dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

instead of

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd/hh-mm");

where 'z' means timezone

Upvotes: 2

Related Questions