I have a unique composite key which is a mixture of a simple stringifed JSON structure concatenated with a Date. It is a fairly complicated looking ID.
"{ foo: bar}Sun Apr 22 2012 12:58:01 GMT+0100 (BST)"
I need a process which translates this string to something with a fewer range of characters. Preferably just alpha-numeric. The process does not have to be reversible.
Just run this through some hash function or use Base64 encoding for the whole id-string.
key = window.btoa( id );
One technique you could use it to use the unix format time instead of date.toString()
:
Math.floor(new Date().getTime()/1000)
I tried to find a way of neatly formatting a date but javascript doesn't have anything like strftime()
in C/++ or, um, just about every other language.