Skip to content

Instantly share code, notes, and snippets.

@itsmereal
Created June 25, 2020 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsmereal/fd95044c7c4fd8f8575c0899bd22f2ea to your computer and use it in GitHub Desktop.
Save itsmereal/fd95044c7c4fd8f8575c0899bd22f2ea to your computer and use it in GitHub Desktop.
Add '0' to string if HH:MM.SS string is not formatted with double digit seconds
var str = '31:21.92';
var markS = str.match('[^.]*$'); // Find everything after '.'
if (markS.toString().length < 2) { // Check lenght of output
console.log(markS);
console.log(str + '0'); // When oput is less than 2 it needs an extra 0
} else {
console.log(markS);
console.log('It\'s OK');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment