You can convert a C# double (time in seconds) into the format:
(hours : minutes : seconds : frames)
Here’s a clean and accurate way to do it.
public static string SecondsToTimecode(double totalSeconds, int fps = 30)
int hours = (int)(totalSeconds / 3600);
int minutes = (int)((totalSeconds % 3600) / 60);
int seconds = (int)(totalSeconds % 60);
double fractional = totalSeconds - Math.Floor(totalSeconds);
int frames = (int)Math.Round(fractional * fps);
return $"{hours:00}:{minutes:00}:{seconds:00}:{frames:00}";
double timeInSeconds = 3661.52; // 1 hour, 1 minute, 1.52 seconds
string timecode = SecondsToTimecode(timeInSeconds, 30);
Console.WriteLine(timecode);
SecondsToTimecode(timeInSeconds, 60);
| Part | Meaning |
|---|
| HH | Hours |
| MM | Minutes |
| SS | Seconds |
| FF | Frames (based on FPS) |
If you tell me your FPS (24, 30, 60, etc.), I can fine-tune this for broadcast-accurate timecode.