How to get current date in this date format "2021-05-19T18:27:16.944+05:30" in Java script or Java?
I checked but all were in this format "2021-06-29T04:37:27.796Z". Can anyone tell me what should be format?
Thank you
Solved! Go to Solution.
Views
Replies
Total Likes
Did you try java.time.OffsetDateTime ?
you can refer this code snippet
public static void main(String[] args) {
String strDateTime = "Tue Jun 29 15:37:43 GMT+05:30 2021";
DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("E MMM d H:m:s O u", Locale.ENGLISH);
OffsetDateTime formatedDate= OffsetDateTime.parse(strDateTime, dtfInput);
System.out.println(formatedDate);
}
Please see the link here:
https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#1222-dates
${'yyyy-MM-dd HH:mm:ss.SSSXXX' @ format=properties.date, timezone='GMT+05:30'}
Thanks!
Did you try java.time.OffsetDateTime ?
you can refer this code snippet
public static void main(String[] args) {
String strDateTime = "Tue Jun 29 15:37:43 GMT+05:30 2021";
DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("E MMM d H:m:s O u", Locale.ENGLISH);
OffsetDateTime formatedDate= OffsetDateTime.parse(strDateTime, dtfInput);
System.out.println(formatedDate);
}
Hi @keerthana_hn ,
You can use below code-
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
public class MyDateExample {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z", Locale.getDefault());
sdf.format(new Date());
System.out.println("sdf"+sdf.format(new Date()));
}
}
Result - 2021-06-29T11:39:25 +0530