CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2022-01-07
by Luke Vanzweden

Original Post

Original - Posted on 2011-02-08
by Samuel Meddows



            
Present in both answers; Present only in the new answer; Present only in the old answer;

All the answers listed above just create a new Date, then look at the first part of it. However, JS Dates include timezones. As of writing this (1/6/22 @ 9PM in Eastern/US), if I run:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
let filename = `any_name_${(new Date().toJSON().slice(0,10))}.zip` console.log(`Add here ${filename}`); <!-- end snippet -->
it falsely gives me tommorows date (1/7/22). This is because Date() just looking at the first part of the date is ignoring the timezone.
A better way to do this that takes into account timezones is:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! var yyyy = today.getFullYear();
filename = mm + '-' + dd + '-' + yyyy + '.zip'; console.log(today); <!-- end snippet -->
Adapted from [here][1].

[1]: https://stackoverflow.com/a/4929629/10197738
Use `new Date()` to generate a new `Date` object containing the current date and time.
<!-- begin snippet: js hide: false -->
<!-- language: lang-js -->
var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0! var yyyy = today.getFullYear(); today = mm + '/' + dd + '/' + yyyy; document.write(today);
<!-- end snippet -->
This will give you today's date in the format of mm/dd/yyyy.
Simply change `today = mm +'/'+ dd +'/'+ yyyy;` to whatever format you wish.

        
Present in both answers; Present only in the new answer; Present only in the old answer;