How do I use Date ?

0 favourites
  • 5 posts
  • Hello there;

    How to change time mode to 24 hours instead of 12 ?


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What method are you using to get the time? If you are using the Date plugin, the time is already stored in 24 hour mode and most of the time methods display it that way.

    Date.toString(timestamp) returns the date info followed by HH:MM:SS in 24 hr then time zone

    Date.toTimeString(timestamp) returns HH:MM:SS in 24 hr followed by time zone information

    Date.getHours(timestamp) returns a value between 0 and 23

    If you need to get the timestamp, use Date.get(Y,M,D,h,m,s,milli)

    Read through the documentation to see more uses:

    If you aren't using the date object, we would need to know how you are getting the date and time to be able to help you/

  • InDWrekt

    I use this:


    It shows time as 12

  • As I understand it, the ToLocaleString shows the time in the most common format for the location you are in. If you want to keep using that method, you will have to split the result up and modify the value yourself. You can use the ToLocaleDateString to get the date and join it to the ToLocaleTimeString. You would check if the time is followed by a pm and if it is, add 12 to the hours.

    -> Set text to Date.ToLocaleDateString(Date.Now) & " " & left(int(left (Date.ToLocaleTimeString(Date.Now), 2)) < 12 & right(Date.ToLocaleTimeString(Date.Now), 2) = "PM" ? int(left (Date.ToLocaleTimeString(Date.Now), 2)) + 12 & right(Date.ToLocaleTimeString(Date.Now), 9) : Date.ToLocaleTimeString(Date.Now), 8)

    Another option is just to build the time yourself using the getHours, getMinutes, getSeconds methods.

  • Thank you InDWrekt

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