I have completed my project, I just want to clear my little doubt.
So I will paste only a little part of the code.
Doubt- If I want to add custom colors to day, month and year element or only to day element like we style using ::first-letter selector in css. Then I will have to use getDate(), getMonth(), getFullYear() to get individual parts then style them ?
If yes then how would I style month element because it is 0 based index.
Ithink i would need to convert each value into a string like 0 = “Jan”, 1=“Feb”.
Is this correct way or wrong or is there another better method ?
Your code so far
function formatDateLong(now) {
let options = {
month: "long",
day: "numeric",
year: "numeric"
}
let data = now.toLocaleDateString("en-US", options);
return `Formatted Date (Month Day, Year): ${data}`;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Challenge Information:
Build a Date Conversion Program - Build a Date Conversion Program
you are asking for styling, that is something you can do with HTML and CSS, here you are writing only JavaScript, you can’t use something like ::first-letter
No no, I am sorry I typed like that. I just meant If I want to style all the individual elements then would I need to get each part- MM DD YYYY individually like I said ?
function formatDateLong(now) {
let options = {
month: "long",
day: "numeric",
year: "numeric"
}
let data = now.toLocaleDateString("en-US", options);
return `Formatted Date (Month Day, Year): ${data}`;
}
i get a date like 04/04/2025
I add it to a <p /> element but instead I wanted date in this to be green color, month blue color and year yellow color, then will this method be good to get the date from JS or getDate(), getMonth(), getFullYear() ?
If yes for later part then, how would I style month element because it is 0 based index.
Ithink i would need to convert each value into a string like 0 = “Jan”, 1=“Feb”.
Is this correct way or wrong or is there another better method ?