Get current Date - or the marvelous overcomplicated task of today

  • Hello community :)

    I want to use the current "date" in my C3 game as a string. Apparently there is a solution to this, that is 4 years old, using JavaScript or other 2 year old plugins.

    construct.net/en/forum/construct-2/how-do-i-18/system-date-time-103607

    Is this really the only solution?? Is there another way I'm missing out on? This feels like it should be so much easier :P

    Any advice would be amazing <3

    All the best,

    Chris

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi newt,

    thanks for this one! This plugins was new to me.

    First I thought you can only create own moments and add values in hours. But it seems to also be able to create a timestamp vom Unix and than change its format via js parsing.

    I tried it, and I quiet don't get it :D

    I was hoping for something like "set text to: Year (Get the currect year as string)"

    But sadly it seems to be not that easy.

    Thanks for the link to the plugin and your help so far!

    Best,

    Chris

  • It's all there, just take a look at the example, and visit momentjs.com

  • mybe full JS ?

    mydate = new Date();
    myday = mydate.getDay();
    mymonth = mydate.getMonth();
    myweekday= mydate.getDate();
  • Hi!

    Thank you for your help guys!

    I got it.

    I didn't manage to get moment.js running like suggested by newt but because of your advice LuisCGForte to use full Javascript I found a post by Asmodean and got it working.

    construct.net/en/forum/construct-3/how-do-i-8/convert-unixtime-readable-143677

    I added +1 year (because I want my game to always take place today in a year of time. The +1 on the month was given in Asmodean's example already "Browser.ExecJS("this.myDate.getMonth()")+1" and it makes the month show correctly. I did not quiet get why a 1 needs to be added to the months. But now everything works.

    For any who is interested in how I use it in my game "SESA":

    Instead of having the start date (which is like your highscore) hard coded, so same every game. it will detect the current date as you play and adds one year to it. So the game will be called "SESA - One Year From Now". Since the prologue tells the player that an asteroid struck earth in the near future and now you have to control the Space Exploration and Survival Administration to colonies your solar system and more to come. I just thought its a cool idea to subtly seed the thought of „what would i do/ who would i be/ would i be if an asteroid struck earth in one year from today. How would i live this year... Just a very small detail and a bit of over engineering, as always. Buts thats just me hey

    I hope this helps more people in the future maybe ;)

    Thanks again for your help!

    Best,

    Chris

  • Hi!

    Thank you for your help guys!

    I got it.

    I didn't manage to get moment.js running like suggested by newt but because of your advice LuisCGForte to use full Javascript I found a post by Asmodean and got it working.

    https://www.construct.net/en/forum/construct-3/how-do-i-8/convert-unixtime-readable-143677

    Are you using C3 ?

    C3 don't need the browser to exec JS, you can just right-click and add script directy.

    But if you feel comfortable doing this, no problem.... i think only impact for minor performance

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)