可能重复:
从javascript中的日期减去天数
我有一个JavaScript基本上返回2天前的日期.它如下:
var x;
var m_names = new Array("January", "February", "March",
"April", "May", "June", "July", "August", "September",
"October", "November", "December");
var d = new Date();
var twoDaysAgo = d.getDate()-2; //change day here
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
var x = twoDaysAgo + "-" + m_names[curr_month] + "-" + curr_year;
document.write(x);
Run Code Online (Sandbox Code Playgroud)
假设今天是2012年12月12日,以上将返回2012年12月10日的日期.我不认为这会在我们进入新的月份时动态起作用,或者,将日期从-2更改为-15.它只能从本月3日开始工作.
我怎么能修改这个,所以当它是2012年12月12日今天,我希望它能在15天前将它更新给我,它应该是2012年11月27日......而不是2012年12月3日?
任何帮助赞赏.谢谢!我是一个Javascript新手.
我首选shell命令来完成任务.我有一个非常非常大的文件 - 大约2.8 GB,内容是JSON的内容.一切都在一条线上,我被告知那里至少有150万条记录.
我必须准备文件以供消费.每条记录必须独立.样品:
{"RomanCharacters":{"Alphabet":[{"RecordId":"1",...]},{"RecordId":"2",...},{"RecordId":"3",...},{"RecordId":"4",...},{"RecordId":"5",...} }}
Run Code Online (Sandbox Code Playgroud)
或者,使用以下内容......
{"Accounts":{"Customer":[{"AccountHolderId":"9c585258-c94c-442b-a2f0-1ebbcc274795","Title":"Mrs","Forename":"Tina","Surname":"Wright","DateofBirth":"1988-01-01","Contact":[{"Contact_Info":"9168777943","TypeId":"Mobile Number","PrimaryFlag":"No","Index":"1","Superseded":"No" },{"Contact_Info":"9503588153","TypeId":"Home Telephone","PrimaryFlag":"Yes","Index":"2","Superseded":"Yes" },{"Contact_Info":"acne.pimple@microchimerism.com","TypeId":"Email Address","PrimaryFlag":"No","Index":"3","Superseded":"No" },{"Contact_Info":"swati.singh@microchimerism.com","TypeId":"Email Address","PrimaryFlag":"Yes","Index":"4","Superseded":"Yes" }, {"Contact_Info":"christian.bale@hollywood.com","TypeId":"Email Address","PrimaryFlag":"No","Index":"5","Superseded":"NO" },{"Contact_Info":"15482475584","TypeId":"Mobile_Phone","PrimaryFlag":"No","Index":"6","Superseded":"No" }],"Address":[{"AddressPtr":"5","Line1":"Flat No.14","Line2":"Surya Estate","Line3":"Baner","Line4":"Pune ","Line5":"new","Addres_City":"pune","Country":"India","PostCode":"AB100KP","PrimaryFlag":"No","Superseded":"No"},{"AddressPtr":"6","Line1":"A-602","Line2":"Viva Vadegiri","Line3":"Virar","Line4":"new","Line5":"banglow","Addres_City":"Mumbai","Country":"India","PostCode":"AB10V6T","PrimaryFlag":"Yes","Superseded":"Yes"}],"Account":[{"Field_A":"6884133655531279","Field_B":"887.07","Field_C":"A Loan Product",...,"FieldY_":"2015-09-18","Field_Z":"24275627"}]},{"AccountHolderId":"92a5788f-cd8f-423d-ae5f-4eb0ceb457fd","_Title":"Dr","_Forename":"Christopher","_Surname":"Carroll","_DateofBirth":"1977-02-02","Contact":[{"Contact_Info":"9168777943","TypeId":"Mobile Number","PrimaryFlag":"No","Index":"7","Superseded":"No" },{"Contact_Info":"9503588153","TypeId":"Home Telephone","PrimaryFlag":"Yes","Index":"8","Superseded":"Yes" },{"Contact_Info":"acne.pimple@microchimerism.com","TypeId":"Email Address","PrimaryFlag":"No","Index":"9","Superseded":"No" },{"Contact_Info":"swati.singh@microchimerism.com","TypeId":"Email Address","PrimaryFlag":"Yes","Index":"10","Superseded":"Yes" }],"Address":[{"AddressPtr":"11","Line1":"Flat No.14","Line2":"Surya Estate","Line3":"Baner","Line4":"Pune ","Line5":"new","Addres_City":"pune","Country":"India","PostCode":"AB11TXF","PrimaryFlag":"No","Superseded":"No"},{"AddressPtr":"12","Line1":"A-602","Line2":"Viva Vadegiri","Line3":"Virar","Line4":"new","Line5":"banglow","Addres_City":"Mumbai","Country":"India","PostCode":"AB11O8W","PrimaryFlag":"Yes","Superseded":"Yes"}],"Account":[{"Field_A":"4121879819185553","Field_B":"887.07","Field_C":"A Loan Product",...,"Field_X":"2015-09-18","Field_Z":"25679434"}]},{"AccountHolderId":"4aa10284-d9aa-4dc0-9652-70f01d22b19e","_Title":"Dr","_Forename":"Cheryl","_Surname":"Ortiz","_DateofBirth":"1977-03-03","Contact":[{"Contact_Info":"9168777943","TypeId":"Mobile Number","PrimaryFlag":"No","Index":"13","Superseded":"No" },{"Contact_Info":"9503588153","TypeId":"Home Telephone","PrimaryFlag":"Yes","Index":"14","Superseded":"Yes" },{"Contact_Info":"acne.pimple@microchimerism.com","TypeId":"Email Address","PrimaryFlag":"No","Index":"15","Superseded":"No" },{"Contact_Info":"swati.singh@microchimerism.com","TypeId":"Email Address","PrimaryFlag":"Yes","Index":"16","Superseded":"Yes" }],"Address":[{"AddressPtr":"17","Line1":"Flat No.14","Line2":"Surya Estate","Line3":"Baner","Line4":"Pune ","Line5":"new","Addres_City":"pune","Country":"India","PostCode":"AB12SQR","PrimaryFlag":"No","Superseded":"No"},{"AddressPtr":"18","Line1":"A-602","Line2":"Viva Vadegiri","Line3":"Virar","Line4":"new","Line5":"banglow","Addres_City":"Mumbai","Country":"India","PostCode":"AB12BAQ","PrimaryFlag":"Yes","Superseded":"Yes"}],"Account":[{"Field_A":"3288214945919484","Field_B":"887.07","Field_C":"A Loan Product",...,"Field_Y":"2015-09-18","Field_Z":"66264768"}]}]}}
Run Code Online (Sandbox Code Playgroud)
最终结果应该是:
{"RomanCharacters":{"Alphabet":[{"RecordId":"1",...]},
{"RecordId":"2",...},
{"RecordId":"3",...},
{"RecordId":"4",...},
{"RecordId":"5",...} }}
Run Code Online (Sandbox Code Playgroud)
尝试的命令:
sed -e 's/,{"RecordId"/}]},\n{"RecordId"/g' sample.datawk '{gsub(",{\"RecordId\"",",\n{\"RecordId\"",$0); print $0}' sample.dat尝试的命令对于小文件非常适用.但它不适用于我必须操作的2.8 GB文件.在没有任何理由的情况下,塞德在10分钟后中途退出,没有做任何事情.经过多个小时后,awk出现了分段错误(核心转储)的原因.我尝试了perl的搜索和替换,并收到错误消息"Out of memory".
任何帮助/想法都会很棒!
我的机器上的其他信息:
我有一个基本上评估 2 个十进制数的脚本。
if (( $(echo "$p $q" | awk '{ print ($1 < $2)}') )); then
echo "Evaluation: Acceptable!"
Run Code Online (Sandbox Code Playgroud)
q 是来自用户输入的小数或数字。
p 是计算出的数字。
因此,如果 p=1 且 q=2,则结果是可接受的。
问题#1
如果计算出的 p 为 -150,而 q=2,我们如何将其评估为不可接受的。基本上,如果 p 小于 0 或负值,结果应该是不可接受的。
问题#2
q 是一个范围:-q < 0 < q
示例:用户输入 q=0.01
可接受范围:-0.01 到 0.01
如果 p 在此范围内,则它是可接受的,否则不可接受。
有任何想法吗?
我知道 Notepad++ 中有一个相当强大的功能,您可以在整个文档中搜索特定字符串并计算其出现次数。这就是查找功能 (Ctrl+F) 中的全部内容。
例如数据:错误读取文件错误读取文件第 3 行错误错误读取文件第 5 行错误
查找和计数*:“行”= 2
I could not seem to find this* function in Geany. If there is already a plugin for this, please share it. Otherwise, please share on how would one do the same -- without switching to another editor.
在阅读了如何在Bash中初始化数组并看到博客中提出的一些基本示例之后,其实际应用仍存在一些不确定性.一个有趣的例子可能是按升序排序 - 按随机顺序列出从A到Z的国家/地区,每个字母一个.
但在现实世界中,Bash阵列是如何应用的?它适用于什么?数组的常见用例是什么?这是我希望熟悉的一个领域.任何使用bash数组的冠军?请提供你的例子.
awk ×2
bash ×2
arrays ×1
geany ×1
if-statement ×1
javascript ×1
json ×1
large-files ×1
linux ×1
perl ×1
shell ×1
text-editor ×1