1

I have an array of

struct {
    Date         time.Time
    PostedSample int
}

loaded from the appengine datastore which I want to output in a html/template for the Google Visualization Time Line. First I tried formatting the Date directly in the template with {{.Date.Format "new Date(2006,1,2,15,4,5)"}} but html/template escapes this so it appears as a quoted string in the html source. I then tried formatting the date into a []struct{Date template.JS; Value template.JS} with the expression template.JS(m.Date.Format("new Date(2006,1,2,15,4,5)")) which almost works except the month is off by one, javascript wants January as 0. I could have the template generate a json of date parameters and write javascript turn that into Date objects or have go code which adjusts the template output. Please share a more elegant solution. Thank you.

2

1 Answer 1

1

You don't need to add a format function to the templates.

You can use your struct like so:

{{.Date.Format "Mon 2 Jan 2006"}}

The solution might be something like this:

var date = new Date(parseInt({{.Date.Nanosecond }} /1000));

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.