For an input date of “23-SEP-2021 00:00” we're getting output of September 22, 2021, but for
“17-SEP-2021 00:00:00" it returns September 17, 2021.
Code looks like this:
export const formatDate = (date) => {
return dayjs(date).format('MMMM DD, YYYY');
};
I've been looking at dayjs format, and I'm not sure what is causing this. I suspect it's either my input month is abbreviated (but probably not since both use SEP), or the different digits in the time (00:00 vs 00:00:00). Searching online I can't find confirmation that it's the time digit difference. Any ideas, or why it would be the time part?
Update: I'm trying to use jsfiddle or chrome console to try this out so I don't have to modify the whole web page to see what changes would do. I tried codePen Playground, but I don't think I'm seeing how to run it there. I also tried at the chrome dev console as shown but got errors that I'm not sure how to fix:
>dayjs(“17-SEP-2021 00:00:00" ).format('MMMM DD, YYYY');
Uncaught SyntaxError: Cannot use import statement outside a module
>require('dayjs')
Uncaught ReferenceError: require is not defined
at <anonymous>:1:1
Trying a snippet, it's giving error regarding dayjs not being defined. I must be doing something wrong. I used this example, but the example didn't give info on how to include dayjs. I have dayjs in there, but for some reason it's only showing when I edit the question.
//var date = new Date("23-SEP-2021 00:00");
//date = date.toLocaleTimeString('en-US', {timeZone: 'America/New_York'});
//console.log(date);
//console.log(dayjs(date).format('MMMM DD, YYYY'));
console.log(dayjs("2021-09-23T00:00:00-04:00").format('MMMM DD, YYYY'));
<script src="https://cdn.jsdelivr.net/npm/dayjs@1.10.7/dayjs.min.js" integrity="sha256-DLRq9d+sak+DFd9tNntiDhbit2Ap2DBlVfh7l9o+LNM=" crossorigin="anonymous"></script>
Update2: Looking at module, it seems like this might be applicable but I can't figure out how to use it with my snippet. Any ideas?
Update3: Added to the snippet trying to add time zone but making the date string into time zone, is returing time instead of date, which dayjs doesn't like. How do I format this with time zone?