If I understand your purpose correctly, you can directly use the SimpleDateFormat class.
Code example:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.UK); String formattedDate = sdf.format(new Date());
You can see the documentation in SimpleDateFormat
Sincerely.
source share