Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created October 22, 2021 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/9234f78b5207f7de2bff38a9d2b4f98b to your computer and use it in GitHub Desktop.
Save parzibyte/9234f78b5207f7de2bff38a9d2b4f98b to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func main() {
/*
https://parzibyte.me/blog
*/
fecha := "2021-10-21T22:12:53"
fechaComoTime, err := time.Parse("2006-01-02T15:04:05", fecha)
if err != nil {
fmt.Println("Error parseando fecha")
fmt.Println(err)
return
}
// Hasta aquí todo bien
fmt.Println("Fecha original: ")
fmt.Println(fechaComoTime)
dentroDeUnaHora := fechaComoTime.Add(time.Hour * 1)
fmt.Println("Fecha dentro de una hora: ")
fmt.Println(dentroDeUnaHora)
haceDosDias := fechaComoTime.Add((time.Hour * 24 * 2) * -1)
fmt.Println("Fecha hace dos días")
fmt.Println(haceDosDias)
dentroDe57Dias := fechaComoTime.Add(time.Hour * 24 * 57)
fmt.Println("Fecha dentro de 57 días:")
fmt.Println(dentroDe57Dias)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment