Loading...
Loading...
Complete guide to working with timestamps in Golang. Learn time package, reference time formatting, timezone handling, and best practices. Copy-paste ready code examples.
Complete guide to working with timestamps in Go. Learn time package, formatting, and best practices.
Get current Unix timestamp in Go
package main
import (
    "fmt"
    "time"
)
func main() {
    // Get current Unix timestamp in seconds
    now := time.Now()
    unixSeconds := now.Unix()
    fmt.Println("Unix seconds:", unixSeconds) // 1729584000
    
    // Get Unix timestamp in milliseconds
    unixMilli := now.UnixMilli()
    fmt.Println("Unix milliseconds:", unixMilli) // 1729584000000
    
    // Get Unix timestamp in nanoseconds
    unixNano := now.UnixNano()
    fmt.Println("Unix nanoseconds:", unixNano)
    
    // Get Unix timestamp in microseconds
    unixMicro := now.UnixMicro()
    fmt.Println("Unix microseconds:", unixMicro)
}Convert Unix timestamp to time.Time object
package main
import (
    "fmt"
    "time"
)
func main() {
    // From Unix seconds
    timestamp := int64(1729584000)
    t := time.Unix(timestamp, 0)
    fmt.Println(t) // 2024-10-22 01:20:00 +0000 UTC
    
    // From Unix milliseconds
    timestampMilli := int64(1729584000000)
    t2 := time.UnixMilli(timestampMilli)
    fmt.Println(t2)
    
    // From Unix microseconds
    timestampMicro := int64(1729584000000000)
    t3 := time.UnixMicro(timestampMicro)
    fmt.Println(t3)
    
    // Format the time
    formatted := t.Format("2006-01-02 15:04:05")
    fmt.Println(formatted) // "2024-10-22 01:20:00"
}Parse date strings and convert to timestamps
package main
import (
    "fmt"
    "time"
)
func main() {
    // Parse RFC3339 (ISO 8601)
    str := "2024-10-22T01:20:00Z"
    t, err := time.Parse(time.RFC3339, str)
    if err != nil {
        panic(err)
    }
    fmt.Println(t.Unix()) // 1729584000
    
    // Parse custom format
    customStr := "2024-10-22 01:20:00"
    layout := "2006-01-02 15:04:05"
    t2, err := time.Parse(layout, customStr)
    if err != nil {
        panic(err)
    }
    fmt.Println(t2.Unix())
    
    // Parse with timezone
    loc, _ := time.LoadLocation("America/New_York")
    t3, _ := time.ParseInLocation(layout, customStr, loc)
    fmt.Println(t3.Unix())
}time.Now().Unix()time.Now().UnixMilli()time.Now().UnixNano()time.Unix(sec, 0)time.UnixMilli(ms)time.UnixMicro(micro)t.Format("2006-01-02")t.Format(time.RFC3339)t.Format("01/02/2006")time.Parse(layout, str)time.ParseInLocation(...)time.ParseDuration(str)了解更多关于这个强大工具
此工具为您的时间戳需求提供基本功能。
旨在帮助您高效处理时间戳。
节省时间并提高时间戳操作的准确性。
Discover what makes this tool powerful
Professional go timestamp with comprehensive functionality. Industry-leading go timestamp providing accurate results and advanced features for all your needs.
Lightning-fast go timestamp with real-time results. Optimized go timestamp algorithms providing immediate accurate calculations and conversions.
All go timestamp operations happen locally in your browser. No data sent to servers, ensuring complete privacy for your operations.
Intuitive go timestamp interface designed for ease of use. Clear displays and helpful guides make the go timestamp accessible to everyone.
Go Timestamp working across all platforms and browsers. Compatible go timestamp supporting desktop, mobile, and tablet devices.
Completely free go timestamp with no registration required. Full-featured go timestamp available at no cost with unlimited usage.
专业级时间戳处理,企业级可靠性
简单步骤有效使用此时间戳工具
在工具提供的输入字段中输入您的时间戳或日期值。
选择您首选的输出格式和任何转换的附加选项。
以高准确性和精度即时查看转换结果。
将结果复制到剪贴板,并在您的应用程序或项目中使用。
Explore more timestamp conversion and calculation tools