Skip to content

jakoivis/utcoffset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

utcoffset

Converts UTC offset formats ±[hh]:[mm], ±[hh][mm], ±[hh] e.g. +02:34, +0234, +02 to seconds. Allows using case insensitive UTC prefix e.g. UTC+02:34, UTC+0234, UTC+02

Example usage

package main

import (
	"fmt"
	"time"

	"github.com/jakoivis/utcoffset"
)

func main() {
	offset := "+0200"

	if utcoffset.IsValidUtcOffset(offset) {
		fmt.Printf("%v is valid\n", offset)
	} else {
		fmt.Printf("%v is not valid\n", offset)
	}

	seconds, err := utcoffset.UtcOffsetSeconds(offset)

	if err != nil {
		fmt.Println(err)
	}

	fmt.Printf("UTC offset %v is in seconds %v\n", offset, seconds)

	location := time.FixedZone("myzone", seconds)

	fmt.Println(time.Now().In(location))
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages