UTC Date Format

Hi,

I am trying to get current date to display in zulu time.
This displays date in yyyy-MM-dd
"dateAsserted": "{{ dateInZone "2006-01-02" (now) "UTC"}}"
but something like this breaks the template (using sprig function)
"dateAsserted": "{{ dateInZone "2006-01-02T14:00:00.000Z" (now) "UTC" }}"

This breaks too.
` “dateAsserted”: “{{ dateInZone “2006-01-02T14:00:00” (now) “UTC” }}”

I am not keen on introducing another library like momentjs because I want to do this within the go template.

Also how do you prevent \ being added (escaped) in the go template if there is an &? This breaks json. I can’t add & either at the template complains.

Hi @tej-rana,

I find it works this way
"dateAsserted": "{{ dateInZone "2006-01-02 15:04:05" (now) "UTC" }}"

and like this, if you want the timezone displayed as well
"dateAsserted": "{{ dateInZone "2006-01-02 15:04:05 MST" (now) "UTC" }}"

Reference got from here.

Also how do you prevent \ being added (escaped) in the go template if there is an & ? This breaks json. I can’t add & either at the template complain

Using “replace” might work. Are you able to provide a sample/more context? input and expected output?

"dateAsserted": "{{ dateInZone "2006-01-02 15:04:05" (now) "UTC" }}" outputs time correctly but is there a way to output 2006-01-02T14:00:00.000Z ?

"dateAsserted": "{{ dateInZone "2006-01-02T15:04:05.000Z" (now) "UTC" }}"

Reference