1

I did an array with some properties incl Date. But the problem is that I have a " Now " Date, and I want to specify a date in Date() like : 20/10/2018 ... Not Today.

Here's the code :

articles = [
    {
      titre: "Mon premier Article",
      contenu:
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
      dateCreation: Date()
    },
    {
      titre: "Mon second Article",
      contenu:
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
      dateCreation: Date()
    },
    {
      titre: "Mon troisième Article",
      contenu:
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
      dateCreation: Date()
    }
  ]; 

Thank you.

TheScripterX
  • 248
  • 3
  • 14
  • Possible duplicate of [How to create a date object from string in javascript](https://stackoverflow.com/questions/8224459/how-to-create-a-date-object-from-string-in-javascript) – Igor May 15 '19 at 17:13
  • @Igor I tried, Not Working. – TheScripterX May 15 '19 at 17:20
  • If you want more help you will have to include what you "tried". [edit] your question and add **exactly** what you tried and the result. "tried" and "not working" could both mean anything. – Igor May 15 '19 at 17:22

2 Answers2

0

You can do this by initialing your date by like new Date('Year,Month,Day) date = new Date('2019','05','19') will return Wed Jun 19 2019 00:00:00 GMT+0500

0

It's Working now !

I just needed to change it in the array and remove "Date ()" and put the value I wanted instead and it's done with the Date type.

Like this :

articles = [
    {
      titre: "Mon premier Article",
      contenu:
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
      **dateCreation: "2018 / 10 / 25"**

Thank you all for your help !

TheScripterX
  • 248
  • 3
  • 14
  • If you want an actual date use: `dateCreation: new Date(2018,10,25)`. If you want to store/communicate a date as a string use ISO8601 notation so the value can't be misconstrued: `dateCreation: "2018-10-25"` – Igor May 15 '19 at 17:35