Build a Date Conversion Program - Build a Date Conversion Program

Tell us what’s happening:

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 ?

then I don’t understand what you mean with “style”, what do you want the result to be?

imagine I got current date with this function-

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 ?

how and where? this is only JavaScript, you can’t have HTML and CSS if it’s only a JavaScript environment

I am asking for a real life scenario, I already completed this project. I am just asking because I have a idea in my mind.

show your idea then, with an html page

with code it’s difficult to talk of hypotheticals

okay I will share it after eating. Can I share it on discord ?

keeping a discussion in a single place keeps it more organized, but it’s your code

I was asking so because last time when I shared a link to my code in replit, then it required a moderator’s approvals which takes time.

I am sorry for replying so late, I didn’t code for more than 15 mins yesterday, I was not well.

Anyways, I tried what I trying to say it here, I got my answer.
Thank you very much for your help :slight_smile: