Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

nodejs 中 mongoose created_at 时间问题

mongoose 中 created_at字段的默认值 Date.now 是不是不能设置时区?如何设置?(默认: 都是格林威治时间)

created_at: { type: Date, default: Date.now }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

没这个必要吧。用的时候再把时间偏移到需要的时区啊,或者用toLocalString之类的函数。
default:function(){Date.now() +/- 你需要的时间},这样应该可以保存当前时区的时间


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...