Commit 00ced75
committed
feat(datetime-api): add DateDemo2 demonstrating epoch time and Long.MAX_VALUE
What
- Added DateDemo2 class to demonstrate working with epoch-based time in Java.
- Shows:
- System.currentTimeMillis() → milliseconds since 1st Jan 1970 (Unix epoch).
- Long.MAX_VALUE → maximum value storable in a long, useful for understanding limits of time representation.
Why
- Introduces the concept of epoch time, the foundation for most date/time APIs and system clocks.
- Helps developers understand how Java internally represents dates and times.
- Provides context on range limitations when storing time values in long.
How to use
- Run DateDemo2.
- Output will display:
1. Current epoch time in milliseconds.
2. Long.MAX_VALUE, showing the upper bound of long type.
Real-life applications
- Epoch time is widely used in:
- Logging frameworks (timestamps).
- Databases (storing created_at/updated_at fields).
- Distributed systems (event ordering, synchronization).
- Scheduling jobs relative to current system time.
- Long.MAX_VALUE awareness helps when working with time calculations, avoiding overflow errors.
Notes
- Epoch time in Java is always measured from 1st Jan 1970 UTC.
- System.currentTimeMillis() is affected by system clock changes; for monotonic time use System.nanoTime().
- Long.MAX_VALUE corresponds to approximately 292 million years in milliseconds → practically “infinite” for real-world use.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent a362ace commit 00ced75
1 file changed
+2
-3
lines changedLines changed: 2 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
7 | | - | |
| 6 | + | |
0 commit comments