I am trying to convert a pst time stamp to gmt in java
I have a string with the time stamp of 2021-03-23T22:00:00.669-07:00
. How would I go about that string and convert to a gmt timestamp?
2021-03-24T05:03:00.669Z
I did something I attempted, but haven't gone everywhere
//Date date = new Date(str);
String s = str;
DateFormat pstFormat = new SimpleDateFormat();
DateFormat gmtFormat = new SimpleDateFormat();
TimeZone gmtTime = TimeZone.getTimeZone("GMT");
TimeZone pstTime = TimeZone.getTimeZone("PST");
pstFormat.setTimeZone(gmtTime);
gmtFormat.setTimeZone(pstTime);
System.out.println("GMT Time: " + pstFormat.format(s));
System.out.println("PST Time: " + gmtFormat.format(s));
The result is java.lang.IllegalArgumentException: Cannot format given Object as a Date
in this line:
System.out.println("GMT Time: " + pstFormat.format(s));