Reputation: 1381
How to make the date to have a GMT offset like mentioned here
import java.util.*;
import java.text.*;
import java.lang.*;
class TFTest
{
public static void main(String[] args)
{
SimpleDateFormat sdf = new SimpleDateFormat("dd MMM, yyyy z");
Date dt = new Date();
System.out.println("\n\n\nparsed date:"+sdf.format(dt)+"\n\n");
}
}
the above program outputs the value as parsed date:02 Aug, 2016 IST.
But I want the value to be parsed date:02 Aug, 2016 GMT +05:30
How to get in the specified format ..?
Upvotes: 1
Views: 593
Reputation: 205
This pattern "dd MMM, yyyy z ZZZZ" will print in the given format
Format formatter = new SimpleDateFormat("dd MMM, yyyy z ZZZZ");
Result like : 02 Aug, 2016 GMT +0000
Upvotes: 0
Reputation: 23
Try, for more documentation visit simpledateformat "dd MMM, yyyy 'GTM' XXX"
Upvotes: 1
Reputation: 44965
The pattern that should work is dd MMM, yyyy 'GMT' XXX
indeed X is the timezone in ISO 8601 which seems to be what you are looking for.
Output:
parsed date:02 Aug, 2016 GMT +05:30
Upvotes: 1