[Plugin] System date and time

  • Joannesalfa

    U can using the Unixtimestamp.

    U need to save the unixtimestamp as webstorage-localvalue.

    Then compare that saved unixtimestamp with the current unixtimestamp.

    U can do that by setting a "global variable" to the current unixtimestamp while substracting the webstorage-saved unixtimestamp.

    Every tick: set global variable to date.getunixtimestamp-webstorage.localvalue("save unixtimestamp")

    The key is to calculate the data "from" that global variable.

    So u can calculate the weeks/days/hours/minutes/seconds.

    The global variable is set as the "difference" between past time and present time.

    If i am correct u can calculate the days by dividing that "difference" by 864.

    That leaves u with a big number which u would need to set to "floor" or "int" to get only the number before the (.)

    Maybe not everything i type here is spot on because im not at my pc right now, but u get the general idea.

  • Update: (please download plugin at first post)

    Add expression:Date2UnixTimestamp(year, month, day, hours, minutes, seconds, milliseconds) to convert date into timestamp.

    Add optional second parameter into expression:Year(timestamp), expression:Month(timestamp), expression:Date(timestamp), expression:Day(timestamp), expression:Hours(timestamp), expression:Minutes(timestamp), expression:Seconds(timestamp), expression:Milliseconds(timestamp) , to convert timestamp into date.

    So that user could transfer timestamp from/to date.

    Capx

    Savvy001

    Here it is.

  • rexrainbow

    Wow thats fast!

    Thank u Rex, this is the feature that makes my universe app complete!

    The scope of things we can do with this is BIG.

    When im at home tonight im going to code the **** out of my pc ;-)

    U sir, are a true gentelmen!

  • The plugin download link is broken. Is there another link?

  • RedDragon

    Thanks, I had fixed the download link, now it is on my dropbox folder.

  • This may seem like a noobish question, but I'm wondering if this could be used or easily tweaked to get the certain effect I'm looking for. I want to be able to set an initial time and date (not the system time), and have it increment by the time expression so that it is affected by timescale, so any increase or decrease in timescale affects the date and time accordingly.

    Is this doable with this plugin, or am I better off looking into trying my hand on developing it myself?

  • Tybot

    This plugin could not fit your requirement, sorry.

  • rexrainbow: Your plugin seems to work with WP8 device. I got the text changed when I change the date. However, when the date change from 6th to 7th, the number resets to 0 and start increasing from there. So 8th will be 1, 9th will be 2. That's still fine for me since I only want to implement the daily reward system to my game, but still wondering what's going on :)

  • Same thing happens in Windows 8

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Can you add the ability to format unix timestamp to a formatted time like HH:MM, tried adding it myself but it didn't work.

    // create a new javascript Date object based on the timestamp
    // multiplied by 1000 so that the argument is in milliseconds, not seconds
    var date = new Date(unix_timestamp*1000);
    // hours part from the timestamp
    var hours = date.getHours();
    // minutes part from the timestamp
    var minutes = date.getMinutes();
    // seconds part from the timestamp
    var seconds = date.getSeconds();
    
    // will display time in 10:30:23 format
    var formattedTime = hours + ':' + minutes + ':' + seconds;
    
  • Can you add the ability to format unix timestamp to a formatted time like HH:MM, tried adding it myself but it didn't work.

    > // create a new javascript Date object based on the timestamp
    // multiplied by 1000 so that the argument is in milliseconds, not seconds
    var date = new Date(unix_timestamp*1000);
    // hours part from the timestamp
    var hours = date.getHours();
    // minutes part from the timestamp
    var minutes = date.getMinutes();
    // seconds part from the timestamp
    var seconds = date.getSeconds();
    
    // will display time in 10:30:23 format
    var formattedTime = hours + ':' + minutes + ':' + seconds;
    

    It's already inside the plugin.

    Check those 2 functions:

    Date2UnixTimestamp

    UnixtTimestamp

  • Format unix timestamp to a formatted time like HH:MM

    Those function produces a unix time stamp, not what I was asking for. (i.e. 1363058603023)

    I want some expressions to take that number (AN UNIXTIMESTAMP / 1363058603023 ) and convert it to HH:MM or indervidually to Hours, Mins, and seconds so I can display that stamp as a time in UI.

    1363058603023 --> 14:23 / 2:23pm

  • labithiotis

    It might help you.

  • Oh, Data.Hours & Minutes can actually take an argument for time, it doesn't show that when I use the expression so I just assumed it used current time only.

    Thanks

  • labithiotis

    Sorry, I will try to add more description in these expression.

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