Pg.tTypeParser( 1114, str => moment.utc(str).format()) Pg.tTypeParser( 1114, str => str) įorce conversion to UTC using, for example, momentjs: // 1114 is OID for timestamp in Postgres // return string as is Solution # 1ĭisable automatic date parsing by node-postgress and parse dates in your application: // 1114 is OID for timestamp in Postgres // return string as is Of course, you know your server’s timezone and you can convert the date back to the correct value but normally you simply don’t expect the date to be in a timezone other than UTC. And at this point the Date function parses the string and assumes that it is a timestamp in your local timezone! So if your server runs in +2, you will get a date object that says 10:00:00, i.e. The issue is quite simple though: say you save 12:00:00 into your database, then you read this value using node-postgres which by default converts 12:00:00 to a JavaScript date object like this new Date( 12:00:00 ). If you also use timestamps without timezone your code may contain bug! If you make queries to PostgreSQL from NodeJS most likely you are using node-postgres or something built on top of it like pg-promise. Normally, attributes of this type hold date-time values in UTC and the application logic converts these values to the user timezone. PostgreSQL offers a type called timestamp without timezone for storing date-time value without the timezone information.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |