81708

missing Location in call to Time.In

<h3>Question</h3>

When I ues beego/orm to operate postgresql database,there is an error like this "missing Location in call to Time.In".

code example

type dataTest struct { Id int `pk:"auto"` Data time.Time `orm:"auto_now;type(timestamp);null"` } local, _ := time.LoadLocation("UTC") test_time, err := time.ParseInLocation("2006-01-02 15:04:05", "1111-01-25 14:27:07", local) orm.DefaultTimeLoc = time.UTC o,err := orm.NewOrmWithDB("postgres","default",db) temp := new(dataTest) temp.Id = 1 temp.Data = test_time o.Update(temp)
<h3>Answer1:</h3>

This should work:

type dataTest struct { Id int `pk:"auto"` Data time.Time `orm:"auto_now;type(timestamp);null"` } test_time, err := time.ParseInLocation("2006-01-02 15:04:05", "1111-01-25 14:27:07", time.UTC) orm.DefaultTimeLoc = time.UTC o,err := orm.NewOrmWithDB("postgres","default",db) temp := new(dataTest) temp.Id = 1 temp.Data = test_time o.Update(temp)
<h3>Answer2:</h3>

For docker (build multi stage)

Install tzdata after build

RUN apk --no-cache add tzdata

List of time zones available, see: https://golang.org/src/time/zoneinfo_abbrs_windows.go

loc, _ := time.LoadLocation("America/Bogota") now := time.Now().In(loc)

来源:https://stackoverflow.com/questions/48439363/missing-location-in-call-to-time-in

Recommend

  • Toggle classes in a list with Angular
  • App Engine's URLFetch: http GET works locally but not when deployed to GAE on a specific URL
  • React 16.7 Hooks : `react.useState` is not a function
  • An AppBar application not working correctly in Windows 8.x/10 (desktop working area does not get red
  • Cannot connect to X server using docker on OS X - Part II
  • How to change node value using node's current value in SQL with XQuery (SQL Server)
  • Deleting/“Rebasing” rails migrations
  • execute .sql file using command line
  • Docker: unix “who” command doesn't work inside container
  • NOTE or WARNING from package check when README.md includes images
  • How to check if the current repository is the top level git repo
  • JQuery Validate plugin submitting when it shouldn't
  • Making query to find nearest multiple(Lat,Long) from the single(Lat,Long)
  • How to delete first 7 characters of folder name by using batch script?
  • How can I run an Illustrator javascript on all files in a directory?
  • Filtering out choiceless polls in the Django tutorial causes polls in the index to duplicate
  • internal javascript not works in angular2
  • Symfony - Setting Cookie onKernelRequest
  • playing mp3 from nsbundle
  • Autocomplete source from project settings
  • C++ STL stack pop operation giving segmentation fault
  • How to use Streams api peek() function and make it work?
  • reshape/remould data frame to create normalized bar chart and pie chart
  • Google App Engine Datastore: Dealing with eventual consistency
  • How to decleare char *const argv[] in swift [duplicate]
  • php “page caching” solution suggestions for CMS Applications
  • Google App Engine backend servlet not responding
  • How to get rgb from transparent pixel in js
  • Background transfer download task failed when app was closed
  • Make checkout phone field optional for specific countries in WooCommerce
  • Excel VBA : conditional formatting of sheet1 cells from sheet2 values in excel 2007
  • Accessing Arguments, Workflow Variables from custom activities
  • Jersey serializes character value to ASCII equivalent numeric string
  • WPF custom control and direct content support
  • CAS 4 - Not able to retrieve the LDAP groups after successful authentication
  • What does the “id” field in an Android “Google Play Music” broadcast intent correspond to?
  • ReferenceError: TextEncoder is not defined
  • ARKit code issue {unknown error -1=ffffffffffffffff error: Task failed with exit 1}