Skip to content

Instantly share code, notes, and snippets.

@aarongilly
Created February 22, 2022 01:42
Show Gist options
  • Save aarongilly/58163e4387e6e4c6ccfb8e97062e59c2 to your computer and use it in GitHub Desktop.
Save aarongilly/58163e4387e6e4c6ccfb8e97062e59c2 to your computer and use it in GitHub Desktop.
Three examples of single line functions to create tiny timestamps, tiny unique IDs, and parse dates from them.
//This is a few lines of code that produces a base36 timestamp
function mkTt() { return new Date().getTime().toString(36)}
//len is any number between 0 and 10
function mkId(len=3){ return new Date().getTime().toString(36)+"."+Math.random().toString(36).slice(13-len).padStart(len,"0") }
//this will pull the date portion of the mkId and will parse the mkTt
function parseDate(tinyId){new Date(parseInt(tinyId.split(".")[0],36))}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment