Comments (9)
timestamp()是获取时间戳的,时间戳定义为从格林威治时间1970年01月01日00时00分00秒起至现在的总秒数。地球上任何时区在任意时间点的时间戳都是相同的。但是不同时区,相同时间戳对应的当前时间不同。
from carbon.
举得例子可能说的不太明确
fmt.Println(carbon.SetTimezone(carbon.LosAngeles).Parse("2020-01-01").ToTimestamp())
fmt.Println(carbon.SetTimezone(carbon.Shanghai).Parse("2020-01-01").ToTimestamp())
期望的结果应该是上面打印的是洛杉矶1月1号对应的时间戳,下面是北京时间的1月1号对应的时间戳,实际结果2条数据一样都是取得本地时间。。。
因为底层都走的这段代码,这段代码写死了时区是local了
// parseByLayout 通过布局模板解析
func parseByLayout(value string, layout string) (time.Time, error) {
loc, _ := time.LoadLocation(Local)
tt, err := time.ParseInLocation(layout, value, loc)
if err != nil {
err = errors.New("the value \"" + value + "\" can't parse string as time")
}
return tt, err
}
from carbon.
这里没问题,虽然parse()方法确实使用了parseBy Layout()方法,但是并没有将接收的carbon对象的Loc设置为Local。实际上,真正时区起作用的是display. go和getter. go里的方法,这些方法调用的是c. Loc
from carbon.
你举的例子中,洛杉矶和北京1月1号对应的时间戳本来就是一样的,任何时区对应的时间戳都是一样的。时间戳不随时区改变而改变。
from carbon.
from carbon.
不同时区对应的时间戳是相同的,但是同一时间戳对应不同时区的日期不同
from carbon.
from carbon.
from carbon.
已修复
from carbon.
Related Issues (20)
- carbon v1 v2 Parse "0000-00-00" error HOT 1
- Time2Carbon() v2.19 has forward compatibility issues HOT 1
- Is it the best way to unmarshal format "2006-01-02T15:04:05.999999" HOT 1
- How to convert a time zone such as UTC/GMT +0800 to carbon's time zone name HOT 3
- Can you add the function of judging whether it is a legal holiday, regardless of the situation of adjustment HOT 2
- Parse method is too strict and not general enough, I hope it can be smarter, such as the following parsing method, which is relatively efficient and general HOT 3
- DiffInMonths does not consider the positive and negative of the time period HOT 2
- Parsing ISO8601 date with .000Z no longer works. HOT 3
- add sequence generation HOT 1
- why return nil after unmarshal failed HOT 2
- New user experience - method naming HOT 9
- The W format in the FormatString method does not conform to the ISO-8601 standard, and there is no automatic zero padding HOT 1
- carbon is used with grom to automatically create a table structure and report an error HOT 2
- DiffInMonths calculation is invalid HOT 2
- Whether to support carbon.SetTestNow? HOT 5
- Format error HOT 2
- Persian calendar HOT 5
- Loss of precision when time is hour on the hour HOT 1
- why layouts is in Parse function, not in Carbon construct function. HOT 1
- Format not work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carbon.