MySQL:
#SELECT userTimezone FROM USER_PREFERENCE WHERE uid = 1;
SELECT
UploadFileID
, UserID
, Filename AS OrigFilename
, CONCAT(Filename, ' <=== this is my filename') AS Filename
, FilenameHashed
#, CreateTime AS OrigCreateTime
, CONCAT(CreateTime + INTERVAL +8 HOUR, ' UTC') AS CreateTime
FROM UploadFile
ORDER BY UploadFileID DESC
Angular(Client side):
Do it in display side. Convert rawdata is usually not a good practice.
export class MyruleUploadGridComponent implements OnInit {
// Global variables
private gridApi;
private gridColumnApi;
public columnDefs = [
{
field: 'UploadFileID',
headerName: 'UploadFileID',
sortable: true,
sortingOrder: ['asc', 'desc'],
headerTooltip: 'asdf',
},
{
field: 'UserID',
headerName: 'UserID',
},
{
field: 'Filename',
headerName: 'Filename',
},
{
field: 'CreateTime',
headerName: 'CreateTime',
cellRenderer: (params) => {
return new DatePipe('en-Us').transform(params.value + ' UTC', 'short', 'locale')
},
},
];
}
Go(backend):
Method1:
var t time.Time
if t, err = TimeIn(colDef.CreateTime, "Canada/Pacific"); err != nil {
fmt.Printf("err: %v\n", err)
}
colDef.CreateTime = t.String()
func TimeIn(inputTime string, name string) (time.Time, error) {
var t time.Time
var err error
layout := "2006-01-02 15:04:05"
if t, err = time.Parse(layout, inputTime); err != nil {
fmt.Printf("err:%v\n", err)
}
loc, err := time.LoadLocation(name)
if err == nil {
t = t.In(loc)
}
return t, err
}
Method2:
package main
import (
"fmt"
"time"
)
func main() {
d1 := "2020-07-29 21:47:11"
newT1 := AddHour(d1, 51)
fmt.Printf("Adding 1 hour\n: %s\n", newT1)
}
func AddHour(d string, numOfHour int) time.Time {
t, _ := ConvStrToTime(d)
newT := t.Add(time.Hour * time.Duration(numOfHour))
return newT
}
func ConvStrToTime(str string) (time.Time, error) {
layout := "2006-01-02 15:04:05" // Mon Jan 2 15:04:05 -0700 MST 2006
return time.Parse(layout, str)
}