Parsing time zone +07:00

115 views
Skip to first unread message

Константин Иванов

unread,
Jul 2, 2019, 2:11:16 PM7/2/19
to golang-nuts



package main

import (
   
"fmt"
   
"time"
)

const in = "+03:00" // "2019-07-02T19:28:39.403+03:00"

const TIME = "+07:00" // "2006-01-02T15:04:05.999+07:00"

func main
() {
    fmt
.Println(time.Parse(TIME, in))
}


Got << parsing time "+03:00" as "+07:00": cannot parse "3:00" as "+07:00" >>

Godoc says:

Numeric time zone offsets format as follows:

-0700  ±hhmm
-07:00 ±hh:mm
-07    ±hh

Am I doind something wrong or it is bug?

Константин Иванов

unread,
Jul 2, 2019, 2:13:15 PM7/2/19
to golang-nuts
*doing

Martin Schnabel

unread,
Jul 2, 2019, 2:26:39 PM7/2/19
to golan...@googlegroups.com
the format time uses a minus sign '-' instead of a plus

https://play.golang.org/p/pXDXm0KmwTz

have fun!

On 02.07.19 20:11, 'Константин Иванов' via golang-nuts wrote:
>
> https://play.golang.org/p/4Rr2xVGKnQg
>
>
> |
> packagemain
>
> import(
> "fmt"
> "time"
> )
>
> constin="+03:00"// "2019-07-02T19:28:39.403+03:00"
>
> constTIME ="+07:00"// "2006-01-02T15:04:05.999+07:00"
>
> func main(){
>     fmt.Println(time.Parse(TIME,in))
> }
> |
>
>
> Got << parsing time "+03:00" as "+07:00": cannot parse "3:00" as "+07:00" >>
>
> Godoc says:
>
> Numeric time zone offsets format as follows:
>
> -0700 ±hhmm
> -07:00 ±hh:mm
> -07 ±hh
>
> Am I doind something wrong or it is bug?
>
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/5c6cdaa3-b549-4583-aa19-d4231605953e%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/5c6cdaa3-b549-4583-aa19-d4231605953e%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Константин Иванов

unread,
Jul 2, 2019, 2:39:18 PM7/2/19
to golang-nuts
Thank you.


вторник, 2 июля 2019 г., 22:26:39 UTC+4 пользователь mb0 написал:
Reply all
Reply to author
Forward
0 new messages