package utils

import (
    "fmt"
    "time"
)

const LOGTIMEFORMAT = "2006-01-02 15:04:05"

func GetTimeStamp() string {
    t := time.Now()
    return fmt.Sprintf("%d000", t.Unix())
}

func GetYMDH() string {
    t := time.Now().UTC()
    loc, err := time.LoadLocation("Asia/Shanghai")
    if err != nil {
        return t.String()
    }   

    t = t.In(loc)
    return fmt.Sprintf("%04d%02d%02d%02d",
        t.Year(), t.Month(), t.Day(), t.Hour())
}

func utcToZone(t string, zone string) (string, error) {
    d, err := time.Parse(LOGTIMEFORMAT, t)
    if err != nil {
        return "", err 
    }   

    //loc, err := time.LoadLocation("Local")
    loc, err := time.LoadLocation(zone)
    if err != nil {
        return "", err 
    }   

    d = d.In(loc)
    return d.Format(LOGTIMEFORMAT), nil 
}

func zoneToUTC(t string, zone string) (string, error) {
    d, err := time.Parse(LOGTIMEFORMAT+" MST", t+" "+zone)
    if err != nil {
        return "", err 
    }   

    loc, err := time.LoadLocation("UTC")
    if err != nil {
        return "", err 
    }   

    d = d.In(loc)
    return d.Format(LOGTIMEFORMAT), nil 
}

---------------我抄的,不关我事。