What is the best way of working with time?

0 favourites
  • 3 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • I need to be able to select from a list of 12-hour times (ex: 03:30 PM) and save it into an array and then sort it based on time. This will also be stored in localstorage. Now, I've tried many different ways and it always seems there is some difficulty regardless of the method I choose.

    My question is what is the BEST way to work with time? If I use 24 hour time, I am able to sort easily in the array, but then I have to convert it to 12 hour time when displaying to user. Maybe I'm just over-thinking this? lol, I'm just getting tired of changing things around when I'm sure one of you has a better way of manipulating time.

    Thanks for any input!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't think there is an easy way.

    do you need to sort time stretching over more than one day? then I would store the raw unix timestamp. then format it when you display the stored times.

    another option would be to store the time in 24 hour in the y=0 element of the array and the 12 hour format in the y=1 element. then when you sort the array on the x axis it will sort the way you want and display from the second element.

  • AllanR - Thanks for the suggestion! Yes, I was looking into doing that, as it seems to be the best way for the sort and display. The time repeats itself daily so it really isn't a complicated sort. I just have to approach it the best way so I'm not running into any problems down the road.

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