I wanted the date in GMT as String like the javascript code below:
const date = new Date();
date.toGMTString();
I am referring to: Parsing Java String into GMT Date and my code looks like below but this errors out:
private static String getDateGMT() {
Date date = new Date(System.currentTimeMillis());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
System.out.println(sdf.format(date));
return sdf.format(sdf);
}
How do I get the Date in "Thu, 04 Nov 2021 06:50:37 GMT" format?