Skip to content

Instantly share code, notes, and snippets.

@jasonalderman
Last active September 26, 2017 18:53
Show Gist options
  • Save jasonalderman/fe1e7b1d43442d82969f81fd2ffeff76 to your computer and use it in GitHub Desktop.
Save jasonalderman/fe1e7b1d43442d82969f81fd2ffeff76 to your computer and use it in GitHub Desktop.
Type a minute/second timecode (e.g., 2:47) in the top field, and get out a number of seconds (e.g., 167.0) below, and vice-versa. https://rawgit.com/jasonalderman/fe1e7b1d43442d82969f81fd2ffeff76/raw/ef635ba1dbe4362064be2c0853d79cae392c236c/timecode-to-seconds.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>timecode calculator</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
input {
font-size: 54px;
width: 70%;
display: block;
margin: 0.5em;
}
</style>
</head>
<body>
<form>
<input type="text" id="tc" tabindex="1" placeholder="2:47 (enter timecode)"/>
<input type="text" id="result" tabindex="2" placeholder="167 (or enter seconds)" />
</form>
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script>
$(document).ready(function(){
$("input")
.on("focus", function(){
$(this).select();
});
$("#tc")
.on("blur", function(){
var cc = $(this).val().split(':') || ["0","0"];
var res = parseInt(cc[0]*60) + parseInt(cc[1]);
$("#result").val(res);
});
$("#result")
.on("blur", function(){
var cc = parseInt($(this).val()) || 0;
var res = "" + Math.floor(cc/60) + ":" + (cc%60);
$("#tc").val(res);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment