简体   繁体   English

nodejs mssql日期查询返回长格式日期,而不是默认字符串文字

[英]nodejs mssql date query returns long format date instead of default string literal

I have a sql query for a column which takes the value of 'date' when I run SELECT * FROM ConferenceMetaData I get '2018-09-05'. 我有一个SQL查询的列,当我运行SELECT * FROM ConferenceMetaData时,它的值是'date',我得到的是'2018-09-05'。 The '2018-09-05' comes from the DB, but when I run the same SQL code in NodeJS the RecordSet returns "Tue Sep 04 2018 17:00:00 GMT-0700 (Pacific Daylight Time)". '2018-09-05'来自数据库,但是当我在NodeJS中运行相同的SQL代码时,RecordSet返回“ Tue Sep 04 2018 17:00:00 GMT-0700(Pacific Daylight Time)”。

Thus the question is: why am I not getting "2018-09-05" from running SELECT * FROM ConferenceMetaData in NodeJS? 因此,问题是:为什么我在NodeJS中无法通过运行SELECT * FROM ConferenceMetaData得到“ 2018-09-05”?

nodeJS is interpreting the date returned from SQL Server as UTC date/time (2018-09-05 00:00:00) and it is converting that the current timezone, which assuming is PST/PDT would be 4th Sept @ 5pm. nodeJS将从SQL Server返回的日期解释为UTC日期/时间(2018-09-05 00:00:00),并转换为当前时区(假设PST / PDT为9月4日@ 5pm)。

So, the answer is that you ARE getting 2018-09-05 00:00:00 UTC, only it is being expressed in PST/PDT timezone. 因此,答案是您正在获得2018-09-05 00:00:00 UTC,仅以PST / PDT时区表示。 Try looking at the UTC value of the date object in nodeJS. 尝试查看nodeJS中日期对象的UTC值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM