Programming Languages - Date / Time
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
Conversion Between Unix Time and Readable Timestamp
Convert from seconds to time string:
$ date -d @1622999905
Sun Jun 6 10:18:25 PDT 202
In ISO 8601 format:
$ date -d @1622999905 -Iseconds
2021-06-06T17:18:25+00:00
With timezone:
$ TZ=":America/Los_Angeles" date -d @1622999905
Sun 06 Jun 2021 10:18:25 AM PDT
Get Running Time
Java
long start = System.currentTimeMillis();
method();
long end = System.currentTimeMillis();
System.out.println("Time used: " + (end – start));
Create Padded Dates
$ seq -f "%02g" 1 31
01
02
03
04
05
...
C++
Recommended Reading
SponsoredConcepts
- Overview
- Which Programming Languages To Learn
- Compile Time and Runtime
- Standard Libraries
- Build Tools
- Memory Management
- Zero Cost Abstractions
- Design Patterns
- Constructors
- Compatibility
- Closures
- Functional Programming
- Generics
- String Interning
- Coding Conventions
- Main
- Ranges
- Lambda
- Random
- IO
- Operators
- Built-in
- Constants
- Functions
- Generics
- Print
- Pointers
- Annotations
- Quotes
- Destructuring
- Generators
- Imports
- Iterators
- Testing
- Visibility
- Assignment Semantics
- Slices
- SSA
- Versus
Concurrency
Control Flow
Data Structures

