dromara / carbon

A simple, semantic and developer-friendly golang package for time
https://pkg.go.dev/github.com/golang-module/carbon/v2
MIT License
4.77k stars 238 forks source link

"2023-11-08T09:52:48" not support? #202

Closed zsq1234 closed 11 months ago

zsq1234 commented 11 months ago

图片

use:carbon.Parse(v).ToStdTime().UnixMilli() v is "2023-11-08T09:52:48" but get value 18446681938112751616

i find the layouts not contain this format, why or can support it?very thank you 图片

gouguoyin commented 11 months ago

The next version will be added. Currently, you can use ParseByLayout method

carbon.ParseByLayout("2023-11-08T09:52:48", "2006-01-02T15:04:05")
gouguoyin commented 11 months ago

In addition, you can replace

carbon.Parse(v.(string)).ToStdTime().UnixMilli()

with

carbon.Parse(v.(string)).TimestampMilli()
zsq1234 commented 11 months ago

thank you, i will try it.

i now meet question again, "2023-11-18T03:55:27.000+0000" 图片 and i do just like this, but get 0, how can i do with it? 图片

The next version will be added. Currently, you can use ParseByLayout method

carbon.ParseByLayout("2023-11-08T09:52:48", "2006-01-02T15:04:05")
gouguoyin commented 11 months ago

-0700 is a fixed format

carbon.ParseByLayout("2023-11-18T03:55:27.000+0000", "2006-01-02T15:04:05.999-0700").TimestampMilli()   // 1700279727000
zsq1234 commented 11 months ago

Thank you, this solved my problem