github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/common/format.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package common 5 6 import "time" 7 8 // FormatTime returns a string with the local time formatted 9 // in an arbitrary format used for status or and localized tz 10 // or in UTC timezone and format RFC3339 if u is specified. 11 func FormatTime(t *time.Time, formatISO bool) string { 12 if formatISO { 13 // If requested, use ISO time format. 14 // The format we use is RFC3339 without the "T". From the spec: 15 // NOTE: ISO 8601 defines date and time separated by "T". 16 // Applications using this syntax may choose, for the sake of 17 // readability, to specify a full-date and full-time separated by 18 // (say) a space character. 19 return t.UTC().Format("2006-01-02 15:04:05Z") 20 } 21 // Otherwise use local time. 22 return t.Local().Format("02 Jan 2006 15:04:05Z07:00") 23 }