Polyglot CheatSheet - DateTime

Updated: 2020-09-18

Get Current Time

Javascript

var date = new Date();

// date
date.getDate();

// month(0-11)
date.getMonth() + 1;

// year(201x)
date.getFullYear();

// get previous day
date.setDate(date.getDate() - 1);

// get epoch
new Date() - new Date(0);

Bash

Suppose today is 2020-01-01

$ date +%Y%m%d
20200101

Get Running Time

Java

long start = System.currentTimeMillis();
method();
long end = System.currentTimeMillis();

System.out.println("Time used: " + (end – start));