Heim  >  Artikel  >  Backend-Entwicklung  >  Nodejs Date 保存到mysql中时区问题,处理方法

Nodejs Date 保存到mysql中时区问题,处理方法

巴扎黑
巴扎黑Original
2016-11-10 11:38:172264Durchsuche

nodejs中mysql用法

1、建立数据库连接:createConnection(Object)方法 该方法接受一个对象作为参数,该对象有四个常用的属性host,user,password,database。与php中链接数据库的参数相同。属性列表如下:

[javascript] view plaincopy

 

       host: 连接数据库所在的主机名. (默认: localhost)  

port: 连接端口. (默认: 3306)  

localAddress: 用于TCP连接的IP地址. (可选)  

socketPath: 链接到unix域的路径。在使用host和port时该参数会被忽略.  

user: MySQL用户的用户名.  

password: MySQL用户的密码.  

database: 链接到的数据库名称 (可选).  

charset: 连接的字符集. (默认: 'UTF8_GENERAL_CI'.设置该值要使用大写!)  

timezone: 储存本地时间的时区. (默认: 'local')  

stringifyObjects: 是否序列化对象. See issue #501. (默认: 'false')  

insecureAuth: 是否允许旧的身份验证方法连接到数据库实例. (默认: false)  

typeCast: 确定是否讲column值转换为本地JavaScript类型列值. (默认: true)  

queryFormat: 自定义的查询语句格式化函数.  

supportBigNumbers: 数据库处理大数字(长整型和含小数),时应该启用 (默认: false).  

bigNumberStrings: 启用 supportBigNumbers和bigNumberStrings 并强制这些数字以字符串的方式返回(默认: false).   

dateStrings: 强制日期类型(TIMESTAMP, DATETIME, DATE)以字符串返回,而不是一javascript Date对象返回. (默认: false)  

debug: 是否开启调试. (默认: false)  

multipleStatements: 是否允许在一个query中传递多个查询语句. (Default: false)  

flags: 链接标志.  

 

Nodejs new Date()  保存到mysql中,处理

连接的属性 dateStrings 设置为true ,保存的时间加上8个钟

var date = new Date();

date.setHours(date.getHours() + 8);

再save


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn