Comments (6)
from carbon.
complete code:
import (
"fmt"
"github.com/golang-module/carbon/v2"
"testing"
"time"
"xorm.io/xorm"
)
type LogAccess struct {
Id string `xorm:"id pk" json:"id"`
AccessAt carbon.Carbon `json:"access_at"`
LogoutAt time.Time `json:"logout_at"`
}
func TestGet(t *testing.T) {
var err error
driver := "mssql"
source := "server=192.168.2.xxx;port=1433;user id=xx;password=xxx;database=xxx"
db, err = xorm.NewEngine(driver, source)
if err != nil {
fmt.Println(err.Error())
}
db.ShowSQL(true)
db.DatabaseTZ = time.Local
db.TZLocation = time.Local
acc := &LogAccess{}
db.ID("1").Get(acc)
fmt.Println("carbon time:", acc.AccessAt)
fmt.Println("carbon loc: ", acc.AccessAt.Location())
fmt.Println("time.Time:", acc.LogoutAt)
}
print:
== RUN TestGet
[xorm] [info] 2023/12/30 09:01:31.904778 [SQL] SELECT [id], [access_at], [logout_at] FROM [log_access] WHERE [id]=? ORDER BY [id] ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY [1] - 151.112768ms
carbon time: 2023-12-29 23:56:46
carbon loc: UTC
time.Time: 2023-12-29 23:56:46 +0800 CST
--- PASS: TestGet (5.62s)
from carbon.
c := acc.AccessAt.SetTimezome("PRC")
fmt.Println("carbon time:", c)
fmt.Println("carbon loc: ", c.Location())
from carbon.
The issue body's language is not English, translate it automatically, please use English next time. ๐ฏ๐ญ๐ป๐งโ๐คโ๐ง๐ซ๐ง๐ฟโ๐คโ๐ง๐ป๐ฉ๐พโ๐คโ๐จ๐ฟ๐ฌ๐ฟ
fmt.Println("carbon loc: ", acc.AccessAt.SetTimezome("PRC").Location())
from carbon.
Thank you. This method is indeed effective.
In fact, I want it to default to using the local time zone.
I think it would be better if it were set to local time by default in database function func (c *Carbon) Scan(v interface{})
.
Thank you again.
from carbon.
Feat in v2.3.2 and v2.3.2 Released
from carbon.
Related Issues (20)
- The current JSON serialization format is `2006-01-02 15:04:05.999999999`. Is user-defined configuration allowed? HOT 5
- "2023-11-08T09:52:48" not support๏ผ HOT 5
- Rename the func such as `carbon.CreateFromDate()`. HOT 13
- ParseByFormat not supported "U" format HOT 3
- json is reversed, causing the diff series method to be abnormal. What should I do in this case? HOT 5
- Default JSON template settings HOT 1
- Wrong zodiac sign HOT 2
- Starting from v2.3.0, after removing the series of methods such as DateTime, it is extremely inconvenient to insert the birthday (Y-m-d) field with gorm now. What is the best practice HOT 11
- build for windows_386 (untyped int constant) overflows int HOT 6
- How to get time.Duration in two carbon instances? ? HOT 1
- ParseByFormat fails to detect location Location HOT 2
- cannot parse string null HOT 3
- DiffAbsInDuration must upgrade go version to 1.9+ HOT 3
- Can you add the 1.5.5 tag? HOT 4
- Incorrect Parse of 0001-01-01 00:00:00 HOT 7
- How to loadTag a slice list? HOT 1
- IsToday()ใIsYesterday()ใIsTomorrow()in other timeZone is invaild HOT 1
- why tag v1.5.5 is not exist HOT 1
- AddQuarters(-1) incorrect result HOT 3
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.