Countdown to a certain Date?

  • Hello everyone,

    I'd like to make a screen which simply shows todays date and system time, counting down to a certain, specified date.

    Lets say i wanna count from June 1st to June 15th, displayed as simple text in days/hours/minutes/seconds. It's important to have it count down, as i want to show how many days/hours/minutes/seconds are left until this specific date.

    Is that even possible with construct 3?

    Now i get how a normal countdown works but i couldn't understand, how can i specify a certain date in a variable and then get the difference to the time right now (while the code is running), which i need in order to set the countdown.

    If anyone can help me out, i would be extremly thankful.

  • Works great!

    I am curious if you can break the formulas down a bit.

    I am not to familiar with Java Script input.

    Set unixDate

    Browser.ExecJS("new Date('" & textDate & "').getTime() / 1000")

    Please tell what the formula is doing.

    I can only assume it is translating textDate into Unix.

    If so is it the date only or does it include the time?

    Why divide by 1000?

    set difference

    int(unixDate-(unixtime/1000))

    Why divide by 1000?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • JS code converts date (textDate) into Unix Epoch Time - number of seconds that have elapsed since January 1, 1970

    "/1000" because that JS function returns milliseconds, and we need seconds.

    unixtime is a C3 expression, it returns current system time in unix format, also in milliseconds.

  • Thanks for the example.

    Set unixDate
    Browser.ExecJS("new Date('" & textDate & "').getTime() / 1000")
    [/code:315j3yd3]
    
    If unixdate is a C3 system expression, why do you use js?
  • unixtime can only return current time. So to convert any date/time in the future you need to use some external function or addon.

    Rex's "date" addon can also convert to unix time.

    EDIT:

    Actually, you don't need to use C3 expression and can calculate the remaining number of seconds directly in JS:

    Set difference to: Browser.ExecJS("(new Date('" & textDate & "').getTime() - new Date().getTime()) / 1000")

  • Here you go:

    https://www.dropbox.com/s/zui1jyusc43ky ... e.c3p?dl=0

    Hi and sorry to bother you with this old topic but do you know how to do this but online?If I use system date people will hack the countdown for a specific action in my app XD

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