Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to convert Game time Format to 00:00:00


Anyone have an idea how to set the gametime to a 00:00:00 format Basically i want it to be 00:01:08 indicating 1 minute 8 seconds.

Right now it outputs as 1.8 I tried various ways of doing this but none of them does what i want. The only solution i do have is a very long a tedious and unpractical way of comparing every second.

Compare INT if equal to 1 set String to 01, If INT 2 Set String to 02 etc.

Im sure there is an easier way. Just haven't found it yet.

My HUD is configured to print it correctly. I just need the correct format

Product Version: Not Selected
more ▼

asked Aug 01 '14 at 08:40 AM in Using UE4

avatar image

417 25 37 53

avatar image Nebula Games Inc Mar 01 '19 at 05:42 PM

If you only need (minutes:seconds:milliseconds), I have created a custom actor component that will output this format automatically. Simply add the component to any blueprint you want and call the function. Everything else is taken care of under the hood. Code is all "copy/paste" to be blueprint user friendly. If you need hours as well feel free to modify the code, it shouldn't be too difficult.


(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

You can get the seconds by using Modulo. In code you would use the % sign.

 float seconds = GameTimeInSeconds % 60; // 60 because there are 60 seconds in a minute

The way it works is it will remove 60 (or whatever you use) from GameTimeInSeconds until there's less then 60 left. It will then return whatever is left. In this case you remove one minute at a time until there's less then a minute left, and the result is the remaining seconds.

You get the minutes by dividing by 60 and flooring the value. You get the hours by dividing by (60*60) which is 3600, and flooring the value. You can get days by dividing by (60*60*24) and flooring the value.

alt text

h-m-s.png (111.8 kB)
more ▼

answered Aug 01 '14 at 09:01 AM

avatar image

1.2k 27 22 211

avatar image C-Arch Aug 01 '14 at 09:30 AM

Ahh thx i learned something new. However it still does not add a 0 in front of seconds. It will still be 1,2,3 and not 01,02,03.

avatar image Dieselhead Aug 01 '14 at 09:52 AM

Sorry, how about this? I switched the variables to Ints as it was printing it with decimals.

alt text

h-m-s2.png (314.4 kB)
avatar image C-Arch Aug 01 '14 at 10:05 AM

Thx a million dude. The get substring is what i was looking for. Does exactly what i needed.

So you solved the issue i was having and an issue i was going to have with the % modulus tip. Thx again.

avatar image C-Arch Aug 08 '14 at 04:54 AM


How do i mark your answer as the answer?

avatar image DaveHall17 Apr 12 '16 at 04:05 PM

Thanks for this answer I found it really useful . Do you know if it is possible to calculate milliseconds as well ?

avatar image quimnuss Feb 23 '18 at 11:26 AM

This answer is outdated. ue4 has FormatText and ToText advanced settings have minimum number of digits now. See @Divo's answer.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Stumbled across your post while I was trying to do something similar. I figured out a great way to do it that doesn't require a lot of effort! :)

alt text

timespan.png (137.5 kB)
more ▼

answered Apr 04 '17 at 01:40 PM

avatar image

202 10 19 18

avatar image chiefGui Jun 15 '18 at 06:33 PM

Thank you @Divo! You saved the day!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question