Skip to content

Instantly share code, notes, and snippets.

@anyu
Last active July 24, 2023 18:04
Show Gist options
  • Save anyu/d648d2adb45dd799a54d5588b36f9de5 to your computer and use it in GitHub Desktop.
Save anyu/d648d2adb45dd799a54d5588b36f9de5 to your computer and use it in GitHub Desktop.

Revisions

  1. anyu renamed this gist Jul 24, 2023. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. anyu created this gist Jul 24, 2023.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    package main

    import (
    "fmt"
    "time"
    )

    func main() {
    inputDate := "2023-03-10"
    inputTime := "00:00:00"
    locationName := "America/Los_Angeles"

    dateTimeStr := inputDate + " " + inputTime
    location, err := time.LoadLocation(locationName)
    if err != nil {
    fmt.Println("Error loading location:", err)
    return
    }
    parsedTime, err := time.ParseInLocation("2006-01-02 15:04:05", dateTimeStr, location)
    if err != nil {
    fmt.Println("Error parsing date and time:", err)
    return
    }

    unixTimestamp := parsedTime.Unix()

    fmt.Println("Date and Time:", parsedTime)
    fmt.Println("Unix Timestamp:", unixTimestamp)
    }