node.js - nodejs 日期格式化 win上正常 linux下不正常
问题描述
1.这是程序依赖request库node v6.9.5npm v4.5.0
var request = require(’request’)var fs = require(’fs’)var url = ’http://rest.wufazhuce.com/OneForWeb/one/getHpinfo?strDate=’var d = new Date()var downUrl = url + d.toLocaleDateString()request(downUrl, ((error, res, body) => { var content = JSON.parse(body) // console.log(body) console.log(content.hpEntity.strThumbnailUrl) request(content.hpEntity.strThumbnailUrl).pipe(fs.createWriteStream(content.hpEntity.strHpTitle + ’.jpg’))}))
2.这是请求的json数据
{ 'result': 'SUCCESS', 'hpEntity': { 'strLastUpdateDate': '2017-05-09 11:42:51', 'strDayDiffer': '0', 'strHpId': '1702', 'strHpTitle': 'VOL.1675', 'strThumbnailUrl': 'http://image.wufazhuce.com/FunJK0ZcKgrsYo92v1fK7-v5-ZEN', 'strOriginalImgUrl': 'http://image.wufazhuce.com/FunJK0ZcKgrsYo92v1fK7-v5-ZEN', 'strAuthor': '绘画', 'strContent': '我希望心里的夏季和身外的夏季一样完美,让我忘记终年终日的等待。可是心灵没有夏季。我望着夏季走过,自己却留在了冬季。', 'strMarketTime': '2017-05-09', 'sWebLk': 'http://m.wufazhuce.com/one/1702', 'strPn': '', 'wImgUrl': '' }}
问题解答
回答1:downUrl = http://rest.wufazhuce.com/OneForWeb/one/getHpinfo?strDate=5/10/2017
当然是非法的了
var request = require(’request’);var fs = require(’fs’);const util = require(’util’);var url = ’http://rest.wufazhuce.com/OneForWeb/one/getHpinfo?strDate=’;var d = new Date();var downUrl = url + encodeURIComponent(d.toLocaleDateString()); // updates go hereconsole.log(downUrl);request(downUrl, ((error, res, body) => { if (error) {console.error(error); } else {var content = JSON.parse(body);console.log(util.inspect(content, { colors: true, depth: 100 }));//console.log(content.hpEntity.strThumbnailUrl);//request(content.hpEntity.strThumbnailUrl).pipe(fs.createWriteStream(content.hpEntity.strHpTitle + ’.jpg’)); }}));回答2:
可以了还是要引用一个日期格式化的小短库,就用dateformat吧 源码200多行使用dateFormat(new Date(), 'yyyy-mm-dd')即可获取2017-05-10格式日期
相关文章:
1. angular.js - 百度支持_escaped_fragment_吗?2. javascript - vue $set 整个数组3. docker-compose中volumes的问题4. vim - win10无法打开markdown编辑器5. 新手 - Python 爬虫 问题 求助6. 微信开放平台 - ios APP能不能打开微信然后通过微信跳转到指定的URL?7. php mail无法发送邮件8. thinkphp5.1学习时遇到session问题9. python - 管道符和ssh传文件10. css - 移动端 line-height安卓错位,苹果机正常用,缩放解决了,可是又出来了占位的问题
