gotime

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2022 License: MIT Imports: 4 Imported by: 0

README

gotime

Convert string to go time.time

GitHub release (latest SemVer) GitHub Workflow Status GitHub Go Report Card pre-commit

Examples

  • Example 1

time, err := gotime.Parse("2016 07 25")
if err != nil {
    fmt.Println(err) // handle error
}
fmt.Println(time) //2016-07-25 00:00:00 +0000 UTC
  • Example 2

time, err := gotime.Parse("01 January 1970 00:00:00 GMT")
if err != nil {
    fmt.Println(err) // handle error
}
fmt.Println(time) //1970-01-01 00:00:00 +0000 GMT
  • Group Examples
times := []string{"2011-10-10T14:48:00 GMT", "2011-10-10T14:48:00", "2011-10-10T14:48:00.000+09:00", "January 1, 09 00:00:00.00 GMT", "August 7, 2014"}
for _, v := range times {
		fmt.Println(gotime.Parse(v))
	}

OUTPUT

2011-10-10 14:48:00 +0000 GMT, nil
2011-10-10 14:48:00 +0000 UTC, nil
2011-10-10 14:48:00 +9000 UTC, nil
2009-01-01 00:00:00 +0000 GMT, nil
2014-08-07 00:00:00 +0000 UTC, nil

Official Documentation

GoDoc

Documentation

Overview

Example
package main

import (
	"fmt"

	"github.com/emylincon/gotime"
)

func main() {
	time, err := gotime.Parse("2016 07 25")
	if err != nil {
		fmt.Println(err) // handle error
	}
	fmt.Println(time)

	time, err = gotime.Parse("25 07 2016")
	if err != nil {
		fmt.Println(err) // handle error
	}
	fmt.Println(time)

	time, err = gotime.Parse("01 January 1970 00:00:00 GMT")
	if err != nil {
		fmt.Println(err) // handle error
	}
	fmt.Println(time)

}
Output:

2016-07-25 00:00:00 +0000 UTC
2016-07-25 00:00:00 +0000 UTC
1970-01-01 00:00:00 +0000 GMT

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(input string) (parsedTime time.Time, err error)

Parse returns time.Time reprsentation of string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL