Created
November 11, 2014 19:45
-
-
Save iver/de71b99d3ad9531c1788 to your computer and use it in GitHub Desktop.
Year difference between two dates in go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
import "time" | |
func main() { | |
birth, _ := time.Parse("2006-01-02", "2000-11-10") | |
duration := time.Since(birth) | |
t1 := time.Unix(0,duration.Nanoseconds()) | |
// Remember, Thursday, 1 January 1970 is defined as first unix day | |
dif := t1.Year() - 1970 | |
fmt.Printf("Years ->%v", dif ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment