Time and date

var year = new Date(); year = year.getFullYear();
outputs current year

var month = new Date(); month = month.getMonth();
outputs current month number between 0-11

var day = new Date(); day = day.getDate();
outputs current day number

var hour = new Date(); hour = hour.getHours();
outputs current hour

var minute = new Date(); minute = minute.getMinutes();
outputs current minute

var second = new Date(); second = second.getSeconds();
outputs current second

Here are some shoddy javascript bits that you can copy/paste into flowlab expression modules to output things like local current year, month, day, hour, minutes. You should be able to make functional clocks or calendars in this way as well time/date-sensetive events. Here’s an example of a clock also showing the date http://flowlab.io/game/view/935706

The getDate/Month/Hours/etc(); endings use local time on your system

Excuse me? This actually works? About a year ago I was going to request a calendar Behavior, so I could have daily quests, and daily rewards in my game. I could also have a global timer, so it would change day and night at actual hours of day and night, and if you use a PowerUp that takes 5 hours to regenerate, it would do five hours even if you aren’t playing the game, instead of 5 in-game hours. If this actually works, that is fantastic.

I’m going to Star this post, because I’ll probably come back to it in the future.


Yeah with javascript in the expressions you can create variables, strings, arrays, functions, generate random numbers, the only problem is that you can only output integers

So what happens if you export the game and you are offline?

So I’m sitting here thinking, if you export the game to Android or something, and you turn off the Wi-Fi and data, it’s not going to be able to extract the time and date, right? Well, what if I string some behaviors together that if the seconds number isn’t going up, a pop-up appears that says “You must connect to the internet to continue playing this game.”

That would prevent any time related events from breaking. You can make certain events not be accessible if offline. You could make you only be at a play certain modes or mini games if you are offline. Something like that. Just thinking.

The regular getDate(); stuff uses local time on your system, and now i think even the getUTCDate(); just converts the system’s local time to UTC, so being offline shouldn’t matter. Going to edit out the UTC thing in first post

I need UTC though to prevent timezone exploit.

I guess I can always check by changing the time in my settings on the laptop. I guess I don’t really need to export the game, but if anybody with an Android or iPhone wants to export their test and try it out, you can let me know if that changes. I don’t really plan on making any mobile games, I was just personally curious.

I don’t think we can get server time, not using this method anyway.

As long as it’s all based on the UTC clock, I guess it doesn’t really matter if you use a proxy or something to change your location. Still, you said it’s online, but then you said it doesn’t matter if it’s offline because it will get it from your system. That’s the only reason I’m still curious if there’s any bugs or exploits around this.

Let’s say I click a button at noon, I want them to be able to click it again after 5 hours. I could use an expression for time + 5, so in this case it would be 17, 5 pm, and the filter would be set to 17 or greater. Now if they are able to change their time zone, that is something I would need to figure out how to prevent.

I’m off work tomorrow, I can probably spend a few hours looking into this. I’m really glad that you brought this up, because this opens up new ideas for me.

Sorry, for that it just converts your local time to UTC based on your system’s timezone settings. It should all be local times that get retrieved, everything offline.

I think the best solution to prevent time/date exploiting is to use counters to reward them after every 1 hour (or however long) ingame time. So if they change the time ahead, the counter is unaffected. You can save the counter to keep track of different gameplay sessions. Say they only play 48 minutes on day 1, they only need 12 more. Even if they change their time/date, the counter doesn’t change, they still would need to play 12 minutes.

So nice, thanks for sharing it!

I was afraid of that. That means I can’t do daily tasks or rewards then, because people can change their date. Hm… Oh well.

hmmmmmm, this will be useful

Javascript? How did you know about that?

So I can confirm it only works for system clock. Not sure how useful this will be, but if you just want a clock in your game, it does that.

The night and day system still works. People can change their hour it won’t affect that much you know.

It matters if you use dates for events, but if you use time, you can keep setting it to a minute before you unlock the next task or reward. For night and day though it could be useful.