Nips Nips - 11 months ago 40
Javascript Question

How to generate hash from timestamp?

I must generate unique hash - maybe from timestamp. hash must have max 8 chars. How to do it?

For now I have only timestamp:

var t = new Date().getTime();

Answer Source

That may look funny but the following code may work well for the next couple of centuries :)

(+new Date).toString(36);  // "iepii89m"

After that you can extend it with slicing method: (+new Date).toString(36).slice(-8).