Convert UTC date format to what's needed

Need to convert the UTC time zones I stored in my database. Something like this -
2020-02-21 10:29:42.812149 +0000 UTC
and what I expect to get us -
Fri, 21 Feb 2020 13:29:42 +03
Ive got a function that returns the converted version of my Date -

var location, _ = time.LoadLocation("Europe/Minsk")

func convertToResponse(books Book) BookResponse {

	return BookResponse{
		ID:     books.ID,
		Name:   books.Name,
		Author: books.Author,
		Date:   books.Date.In(location).Format(time.RFC1123),

I made an endpoint that selects from the database, but when I run it, the date format is this -

        "id": 19,
        "name": "book19",
        "author": "QWERT",
        "date": "Sat, 01 Jan 0000 12:17:16 LMT"

It didn’t get formatted. and im not sure what’s wrong.
Heres the link to the full code, if you’ll need it -

What exactly is the value of books.Date? Ofbooks.Date.In(location)?

The value of books.Date is -
0000-01-01 10:27:00.138572 +0000 UTC
Its just the date in UTC time zone. In a raw format

The value of books.Date.In(location) should be the converted format of the UTC time zone to the desired location I want

im inserting time.Now().UTC() into the date field in my database, and ‘should’ get a response in this format books.Date.In(location).Format(time.RFC1123)

Maybe this resource will help

1 Like

Does it show the proper UTC if you take the call to In out?

Shows just the date in UTC format

You can get help from offical time package or below -

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.