Nips Nips - 1 year ago 112
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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download