Last active
June 25, 2017 01:24
-
-
Save spiegel-im-spiegel/bcf42df831165123cfc171fadf42eb1d to your computer and use it in GitHub Desktop.
Go 言語における無効日付(2月31日など)の扱い ref: http://qiita.com/spiegel-im-spiegel/items/42d115471cf2b5a80437
This file contains 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" | |
"time" | |
) | |
func main() { | |
tm := time.Date(2017, 1, 31, 0, 0, 0, 0, time.UTC) | |
for i := 0; i < 6; i++ { | |
fmt.Println(tm.Format("2006-01-02")) | |
tm = tm.AddDate(0, 1, 0) | |
} | |
} |
This file contains 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
2017-01-31 | |
2017-03-03 | |
2017-04-03 | |
2017-05-03 | |
2017-06-03 | |
2017-07-03 |
This file contains 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" | |
"time" | |
) | |
func main() { | |
tm := time.Date(2017, 1, 31, 0, 0, 0, 0, time.UTC) | |
for i := 0; i < 6; i++ { | |
fmt.Println(tm.AddDate(0, i, 0).Format("2006-01-02")) | |
} | |
} |
This file contains 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
2017-01-31 | |
2017-03-03 | |
2017-03-31 | |
2017-05-01 | |
2017-05-31 | |
2017-07-01 |
This file contains 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" | |
"time" | |
) | |
func main() { | |
tm := time.Date(2017, 1, 31, 0, 0, 0, 0, time.UTC) | |
for i := 0; i < 6; i++ { | |
fmt.Println(tm.Format("2006-01-02")) | |
tm = time.Date(tm.Year(), tm.Month()+2, 0, 0, 0, 0, 0, time.UTC) | |
} | |
} |
This file contains 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
2017-01-31 | |
2017-02-28 | |
2017-03-31 | |
2017-04-30 | |
2017-05-31 | |
2017-06-30 |
This file contains 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
tm := time.Date(2016, 1, 31, 0, 0, 0, 0, time.UTC) |
This file contains 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
2016-01-31 | |
2016-02-29 | |
2016-03-31 | |
2016-04-30 | |
2016-05-31 | |
2016-06-30 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment