nodejs | lastest |
express | lastest |
swig | lastest |
requirejs | lastest |
bootstrap | lastest |
中国日期错误原因:
症状为明明是23号,用swig date filter后显示日期为22号。
原因是由于swig默认使用的国际标准时区,中国大于国际标准时区8个小时。
时区表:参考百科:http://baike.baidu.com/view/25961.htm?fr=aladdin#6
解决方案:误差减去 480m
{% for e in list %}
<tr>
<td>{= e.id =}</td>
<td>{= e.birthday|date('Y-m-d', -480) =}</td>
<td>{= e.create_at|date('Y-m-d H:i:s', -480, 'CCT') =}</td>
</tr>
{% endfor %}
swig 内容代码解析:
\node_modules\swig\lib\filters.js
exports.date = function (input, format, offset, abbr) { var l = format.length, date = new dateFormatter.DateZ(input), cur, i = 0, out = ''; if (offset) { date.setTimezoneOffset(offset, abbr); }
\node_modules\swig\lib\dateformatter.js
setTimezoneOffset: function (offset) { this.timezoneOffset = offset; this.dateZ = new Date(this.date.getTime() + this.date.getTimezoneOffset() * 60000 - this.timezoneOffset * 60000); return this; }