自己设定的时间格式为:
var time = { date: date, year : date.getFullYear(), month : date.getFullYear() + “-” + (date.getMonth() + 1), day : date.getFullYear() + “-” + (date.getMonth() + 1) + “-” + date.getDate(), minute : date.getFullYear() + “-” + (date.getMonth() + 1) + “-” + date.getDate() + " " + date.getHours() + “:” + (date.getMinutes() < 10 ? ‘0’ + date.getMinutes() : date.getMinutes()) }
但是markdown抛出异常:
/Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/connection/base.js:246 throw message;
^ TypeError: Cannot read property ‘slice’ of null at convert_tree_to_html (/Users/qianjiahao/blog/node_modules/markdown/lib/markdown.js:1556:20) at Object.toHTMLTree (/Users/qianjiahao/blog/node_modules/markdown/lib/markdown.js:112:14) at Object.toHTML (/Users/qianjiahao/blog/node_modules/markdown/lib/markdown.js:82:22) at /Users/qianjiahao/blog/models/post.js:101:25 at /Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/collection/query.js:164:5 at Cursor.nextObject (/Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/cursor.js:753:5) at commandHandler (/Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/cursor.js:727:14) at /Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/db.js:1912:9 at Server.Base._callHandler (/Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/connection/base.js:448:41) at /Users/qianjiahao/blog/node_modules/mongodb/lib/mongodb/connection/server.js:481:18 Process finished with exit code 1
尝试通过“\”来转义,但是转义失败。
var time = { date: date, year : date.getFullYear(), month : date.getFullYear() + “-” + (date.getMonth() + 1), day : date.getFullYear() + “-” + (date.getMonth() + 1) + “-” + date.getDate(), minute : date.getFullYear() + “-” + (date.getMonth() + 1) + “-” + date.getDate() + “-” + date.getHours() + “-” + (date.getMinutes() < 10 ? ‘0’ + date.getMinutes() : date.getMinutes()) }
各位大神有没有什么办法。。。
看报错的情况 你貌似是用了 变量.slice
但是这个变量为null
。
贴得代码里面没那一段。
另外时间格式化,我用moment.js手写好累23333,推荐你去看看
@luicfer 谢谢 ,后来问题解决了,也用上了moment,好爽!
@qianjiahao 自己发现了moment?
@luicfer 我看招聘上要求掌握的模块里有这个,就上npm找了下,然后就用上,飞一样的感觉~~