How to get the day (ex: Monday) from a time Instant in FreeMarker Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of How to get the day (ex: Monday) from a time Instant in FreeMarker without wasting too much if your time.

The question is published on by Tutorial Guruji team.

So I got this Instant date in Java: “2018-05-19T22:00:00Z”.

How can I get the day of the week? like monday..

I was trying this but it doesn’t work:

${date?string["EEEE"]}

Thanks

Answer

Freemarker does not work with Instant, so you would need to convert that to string in Java (something like “2018-05-19T22:00:00Z”) and then convert the string doing the following:

<#setting locale="en_US">
${"2018-05-19T22:00:00Z"?datetime.iso?string["EEEE"]}

First convert the string to datetime in iso format, and then back again to string with the pattern of your choosing.

By changing the locale setting, you may get the day of the week in different languages.

I think that the best way to work in Freemarker is to always have strings or integers variables.

We are here to answer your question about How to get the day (ex: Monday) from a time Instant in FreeMarker - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji