Skip to content

Instantly share code, notes, and snippets.

@luigimannoni
Created February 17, 2022 11:25
Show Gist options
  • Save luigimannoni/71bc96e2459919554c90c6375ff5fb20 to your computer and use it in GitHub Desktop.
Save luigimannoni/71bc96e2459919554c90c6375ff5fb20 to your computer and use it in GitHub Desktop.
Best date format
const now = new Date();
const zodiac = (year) => {
switch ((year - 4) % 12) {
case 0: return 'Rat';
case 1: return 'Ox';
case 2: return 'Tiger';
case 3: return 'Rabbit';
case 4: return 'Dragon';
case 5: return 'Snake';
case 6: return 'Horse';
case 7: return 'Goat';
case 8: return 'Monkey';
case 9: return 'Rooster';
case 10: return 'Dog';
case 11: return 'Pig';
}
}
console.log(`${now.getHours()}:${now.getMonth() + 1}-${now.getFullYear()}-${now.getDate()}:${now.getMinutes()}*${now.getSeconds()}${zodiac(now.getFullYear())}`);
// '11:2-2022-17:21*59Tiger'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment