How to get milliseconds?

public static int getHours(int totalSeconds) { return totalSeconds / 3600; } public static int getMinutes(int totalSeconds) { return (totalSeconds - 3600*getHours(totalSeconds)) / 60; } public static int getSeconds(int totalSeconds) { return totalSeconds - 3600*getHours(totalSeconds) - 60*getMinutes(totalSeconds); } public static int getMilliseconds(int totalSeconds) { return ??? } 
  • one
    in this case - no way - Grundy
  • Can someone explain the author's idea? If he just does not know how many milliseconds in the second, then let him know - there are thousands of them. In this way ??? turn into return 1000 * totalSeconds. - Sergey
  • one
    @Sergey, as I understand it - TimeSpan in seconds and you need to get the components: days, hours, minutes, seconds, milliseconds - Grundy
  • return 1000 * totalSeconds returns such a number 00: 00: 77.77000 ms duplicate seconds - klieve

1 answer 1

Since milliseconds are a fraction of a second, and the parameter is an integer number of seconds, this function can only return - 0.

  • And if you make the variable double instead of int? - klieve
  • Then you take the fractional part and multiply by 1000 - Grundy
  • @klieve, by and large milliseconds can not be taken at all, but output just seconds with a fractional part - Grundy
  • too much code to redo me so much easier to do double for ms - klieve
  • @klieve, well, if you transmit it anyway, int - there will be no difference. he just returns 0 and that's it - Grundy