Skip to content

Instantly share code, notes, and snippets.

@ik5
Created November 9, 2016 09:04
Show Gist options
  • Select an option

  • Save ik5/672405e8d0c10b5fb6f3d5e4a32a95a5 to your computer and use it in GitHub Desktop.

Select an option

Save ik5/672405e8d0c10b5fb6f3d5e4a32a95a5 to your computer and use it in GitHub Desktop.

Revisions

  1. ik5 created this gist Nov 9, 2016.
    56 changes: 56 additions & 0 deletions time_format.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    package main

    import (
    "fmt"
    "time"
    )

    func main() {
    fmt.Println("Times: ")
    t := time.Now()
    loc, err := time.LoadLocation("Asia/Jerusalem")

    if err != nil {
    fmt.Println("Opps: ", err)
    return
    }

    fmt.Printf("Format: dd/mm/yy hh:MM:ss PM Mon - %s \n", t.In(loc).Format("02/01/06 03:04:05 PM Jan"))
    fmt.Printf("Format: dd/mm/yy hh:MM:ss PM Da Mon - %s \n", t.In(loc).Format("02/01/06 03:04:05 PM Mon Jan"))
    fmt.Printf("Format: dd/mm/yy hh:MM:ss PM Day Month - %s \n", t.In(loc).Format("02/01/06 03:04:05 PM Monay January"))
    fmt.Printf("Format: d/m/y h:M:s PM - %s\n", t.In(loc).Format("2/1/6 3:4:5 PM"))
    fmt.Printf("Format: _d/m/y h:M:s PM - %s\n", t.In(loc).Format("_2/1/6 3:4:5 PM"))
    fmt.Printf("Format: dd/mm/yy hh:MM:ss PM - %s \n", t.In(loc).Format("02/01/06 03:04:05 PM"))
    fmt.Printf("Format: dd/mm/yyyy hh:MM:ss PM - %s \n", t.In(loc).Format("02/01/2006 03:04:05 PM"))
    fmt.Printf("Format: dd/mm/yyyy hh:MM:ss.ms PM - %s \n", t.In(loc).Format("02/01/2006 03:04:05.000 PM"))
    fmt.Printf("Format: dd/mm/yyyy hh:MM:ss.000ms PM - %s \n", t.In(loc).Format("02/01/2006 03:04:05.000000 PM"))
    fmt.Printf("Format: dd/mm/yyyy hh:MM:ss.000000ms PM - %s \n", t.In(loc).Format("02/01/2006 03:04:05.000000000 PM"))
    fmt.Printf("Format dd/mm/yyyy hh:MM:ss TZName - %s\n", t.In(loc).Format("02/01/2006 15:04:05 MST"))
    fmt.Printf("Format dd/mm/yyyy hh:MM:ss Z - %s\n", t.In(loc).Format("02/01/2006 15:04:05 Z7"))
    fmt.Printf("Format dd/mm/yyyy hh:MM:ss Z - %s\n", t.In(loc).Format("02/01/2006 15:04:05 Z07"))
    fmt.Printf("Format dd/mm/yyyy hh:MM:ss ZZ - %s\n", t.In(loc).Format("02/01/2006 15:04:05 Z0700"))
    fmt.Printf("Format dd/mm/yyyy hh:MM:ss Z:Z - %s\n", t.In(loc).Format("02/01/2006 15:04:05 Z07:00"))
    fmt.Printf("Format dd/mm/yyyy hh:MM:ss Z:Z - %s\n", t.In(loc).Format("02/01/2006 15:04:05 -07:00"))
    }


    /* Output:
    Times:
    Format: dd/mm/yy hh:MM:ss PM Mon - 09/11/16 10:56:30 AM Nov
    Format: dd/mm/yy hh:MM:ss PM Da Mon - 09/11/16 10:56:30 AM Wed Nov
    Format: dd/mm/yy hh:MM:ss PM Day Month - 09/11/16 10:56:30 AM Monay November
    Format: d/m/y h:M:s PM - 9/11/6 10:56:30 AM
    Format: _d/m/y h:M:s PM - 9/11/6 10:56:30 AM
    Format: dd/mm/yy hh:MM:ss PM - 09/11/16 10:56:30 AM
    Format: dd/mm/yyyy hh:MM:ss PM - 09/11/2016 10:56:30 AM
    Format: dd/mm/yyyy hh:MM:ss.ms PM - 09/11/2016 10:56:30.952 AM
    Format: dd/mm/yyyy hh:MM:ss.000ms PM - 09/11/2016 10:56:30.952216 AM
    Format: dd/mm/yyyy hh:MM:ss.000000ms PM - 09/11/2016 10:56:30.952216972 AM
    Format dd/mm/yyyy hh:MM:ss TZName - 09/11/2016 10:56:30 IST
    Format dd/mm/yyyy hh:MM:ss Z - 09/11/2016 10:56:30 Z7
    Format dd/mm/yyyy hh:MM:ss Z - 09/11/2016 10:56:30 +02
    Format dd/mm/yyyy hh:MM:ss ZZ - 09/11/2016 10:56:30 +0200
    Format dd/mm/yyyy hh:MM:ss Z:Z - 09/11/2016 10:56:30 +02:00
    Format dd/mm/yyyy hh:MM:ss Z:Z - 09/11/2016 10:56:30 +02:00
    */