//Converts a string passed in with the millisecond count to the date in the form yyyy-MM-dd HH:mm:ss as a string
func convertStringToDate64(strDate string) (string, error) {
uD, err := strconv.ParseInt(strDate, 0, 64)
if err == nil {
return time.Unix((uD/(10000000))-11644473600, 0).Format("2006-01-02 15:04:05"), nil
}
return "", nil
}
//Converts a string passed in the form yyyyMMddHHmmss.0Z to the date in the form yyyy-MM-dd HH:mm:ss as a string
func convertStringToDateZ(strDate string) (string, error) {
uD, err := time.Parse("20060102150405", strings.Replace(strDate, ".0Z", "", 1))
if err == nil {
return uD.Format("2006-01-02 15:04:05"), nil
}
return "", nil
}
No words wasted! Getting to the point about the work I do, the problems I deal with, and some links to posts about where I work.
Translate
Friday, April 8, 2022
Golang - Working with active directory date attributes
Some simple functions I wrote to convert AD date attributes to dates as stings.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Thank you for commenting!