JSFiddle - React, Tailwind, and code Playground

by petermorlion

HTML

~~ in JS is a double bitwise NOT. Because the bitwise NOT converts to  the operands to signed integers. Doing it twice has the effect of dropping decimals, rounding down (in case of a positive number) or up (in case of a negative number).<br />
<br />
I wouldn't recommend using this, as it's not very readable, and not very widely known.

<div id="basicExample"></div>

<div id="outputDate"></div>

CSS

* { font-family: Verdana; }
div { border: 1px solid grey; margin-top:10px; padding: 10px;}

JavaScript

var milliseconds = 651406846510;
var seconds = ~~(milliseconds / 1000);
var minutes = ~~(seconds / 60);
var hours = ~~(minutes / 60);
var days = ~~(hours / 24);
var weeks = ~~(days / 7);
var year = ~~(days / 365);

var outputDate = milliseconds + 'ms is <br /><br />' + year + ' years<br />' + weeks + ' weeks<br />' + days + ' days<br />' + hours + ' hours<br />' + minutes + ' minutes<br />' + seconds + ' seconds';

$('#outputDate').html(outputDate);

var basicExample = '~~4.7 is ' + ~~4.7 + '<br />~~-4.7 is ' + ~~-4.7;

$('#basicExample').html(basicExample);