UNIX টাইমস্ট্যাম্প কী?
A UNIX timestamp (also called epoch time, POSIX time, or simply Unix time) is a way to represent a point in time as a single integer — the number of seconds (or milliseconds) elapsed since the UNIX Epoch: January 1, 1970, 00:00:00 UTC.
It is the universal language for time across operating systems, databases, and programming languages because it is timezone-agnostic, compact, and sortable. Any negative value represents a moment before 1970.
Why milliseconds instead of seconds?
The original UNIX standard measured time in seconds. Modern languages (JavaScript, Java) use milliseconds for sub-second precision without floating-point arithmetic. Some systems (Linux clock_gettime, Go's time.Now().UnixNano()) go further with nanoseconds. Always check your language's default unit when working with timestamps.
টাইমস্ট্যাম্প কেন সর্বজনীন?
- কোনো টাইমজোন অস্পষ্টতা নেই — সর্বদা UTC-এর সাপেক্ষে
- একক পূর্ণসংখ্যা — সংরক্ষণ, তুলনা ও প্রেরণ করা সহজ
- স্বাভাবিকভাবে বাছাইযোগ্য — বড় মান = পরবর্তী সময়
- Unambiguous during DST changes — wall-clock times can be ambiguous, timestamps never are
Java-তে System.currentTimeMillis()
System.currentTimeMillis() হলো Java-র বিল্ট-ইন মেথড যা বর্তমান সময়কে জানুয়ারি ১, ১৯৭০ UTC থেকে মিলিসেকেন্ড সংখ্যা হিসেবে রিটার্ন করে। এটি JavaScript-এর Date.now()-এর Java সমতুল্য।
public class TimestampExample {
public static void main(String[] args) {
// Get current time in milliseconds
long millis = System.currentTimeMillis();
System.out.println("Millis: " + millis);
// Convert to Date
java.util.Date date = new java.util.Date(millis);
System.out.println("Date: " + date);
// Modern API (Java 8+) — recommended
java.time.Instant instant = java.time.Instant.ofEpochMilli(millis);
System.out.println("Instant: " + instant);
}
}
Modern Java time API (Java 8+ recommended)
Java 8 introduced the java.time package which is far superior to Date/Calendar.
import java.time.*;
// Current timestamp in milliseconds
long ms = Instant.now().toEpochMilli();
// Current timestamp in seconds
long sec = Instant.now().getEpochSecond();
// Convert millis back to Instant
Instant instant = Instant.ofEpochMilli(ms);
// Format as ISO 8601
String iso = instant.toString(); // "2026-03-16T10:30:00Z"
// Format with timezone
ZonedDateTime zdt = instant.atZone(ZoneId.of("America/New_York"));
String formatted = zdt.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
System.nanoTime() বনাম currentTimeMillis()
System.nanoTime() returns nanoseconds elapsed since some arbitrary origin — it is not tied to the UNIX epoch. Use it only for measuring elapsed time intervals, not for wall-clock timestamps.
// Measure elapsed time (correct)
long start = System.nanoTime();
doSomething();
long elapsed = System.nanoTime() - start;
System.out.printf("Took %.2f ms%n", elapsed / 1_000_000.0);
// Wall clock (correct)
long now = System.currentTimeMillis();
java.time থেকে Instant.now().toEpochMilli() ব্যবহার করুন। এটি অপরিবর্তনীয়, থ্রেড-নিরাপদ এবং System.currentTimeMillis()-এর চেয়ে বেশি প্রকাশমূলক।UTC বোঝা
UTC (Coordinated Universal Time) is the primary time standard by which the world regulates clocks and time. It is the successor to Greenwich Mean Time (GMT) and the basis for all UNIX timestamps.
UTC বনাম GMT — পার্থক্য কী?
GMT (Greenwich Mean Time) is a timezone originally based on the mean solar time at the Royal Observatory in Greenwich, London. UTC is a modern atomic-clock-based standard. They read the same offset (UTC+0 = GMT+0), but UTC is more precise — it includes leap seconds to account for irregularities in Earth's rotation.
- For programming purposes, UTC and GMT are interchangeable. Most databases, APIs, and systems store time in UTC.
- Leap seconds are added to UTC periodically (since 1972) — most computer systems "smear" or skip them and do not expose them to application code.
কেন সবকিছু UTC-তে সংরক্ষণ করবেন?
- Timezone rules change (governments alter DST schedules). UTC never changes.
- Comparing timestamps across timezones is trivial — just compare the UTC values directly.
- ডেলাইট সেভিং টাইম (DST) পরিবর্তন অস্পষ্ট ওয়াল-ক্লক টাইম তৈরি করে। UTC-তে কোনো অস্পষ্টতা নেই।
TIMESTAMP WITH TIME ZONEসহ ডেটাবেস (PostgreSQL, MySQL) অভ্যন্তরীণভাবে UTC-তে মান সংরক্ষণ করে।
Getting UTC time in various languages
const now = new Date();
console.log(now.toUTCString()); // "Mon, 16 Mar 2026 10:30:00 GMT"
console.log(now.toISOString()); // "2026-03-16T10:30:00.000Z"
console.log(Date.now()); // ms since epoch (always UTC)
from datetime import datetime, timezone
# UTC-aware datetime
now_utc = datetime.now(timezone.utc)
print(now_utc.isoformat()) # "2026-03-16T10:30:00+00:00"
# Unix timestamp (seconds)
import time
ts = time.time() # float seconds
টাইমজোনের সাথে কাজ করা
টাইমজোন সফটওয়্যারে বাগের সবচেয়ে সাধারণ উৎসগুলির একটি। এগুলি কীভাবে কাজ করে তা বোঝা — বিশেষত ডেলাইট সেভিং টাইম (DST) — ডিবাগিংয়ের ঘণ্টার পর ঘণ্টা বাঁচায়।
টাইমজোন অফসেট — কীভাবে কাজ করে
একটি টাইমজোন হলো এমন একটি অঞ্চল যা একটি অভিন্ন মান সময় পালন করে। অফসেটগুলি Coordinated Universal Time-এর সাপেক্ষে UTC+HH:MM বা UTC-HH:MM হিসেবে প্রকাশ করা হয়।
UTC+05:30= ইন্ডিয়া স্ট্যান্ডার্ড টাইম (IST) — UTC-এর চেয়ে ৫ ঘণ্টা ৩০ মিনিট এগিয়েUTC-05:00= ইস্টার্ন স্ট্যান্ডার্ড টাইম (EST)UTC+09:00= জাপান স্ট্যান্ডার্ড টাইম (JST) — কোনো DST নেই
+05:30-এর মতো টাইমজোন অফসেট হার্ডকোড করবেন না। IANA টাইমজোন নাম ব্যবহার করুন (যেমন "Asia/Kolkata") কারণ রাজনৈতিক সিদ্ধান্তের কারণে অফসেট পরিবর্তন হতে পারে।ডেলাইট সেভিং টাইম (DST) ব্যাখ্যা
DST হলো গ্রীষ্মকালীন মাসগুলিতে সন্ধ্যার দিনের আলো বাড়াতে ঘড়ি ১ ঘণ্টা এগিয়ে নেওয়ার অনুশীলন। এটি অনেক (কিন্তু সব নয়) দেশে পালিত হয়।
সাধারণ DST সমস্যাসমূহ:
- Clocks "spring forward" — 2:00 AM becomes 3:00 AM. The hour between 2-3 AM does not exist.
- Clocks "fall back" — 2:00 AM becomes 1:00 AM again. The hour between 1-2 AM occurs twice.
- Events scheduled at ambiguous times can be mis-scheduled by exactly 1 hour.
// Safe: use Intl.DateTimeFormat with IANA timezone name
const now = new Date();
const fmt = new Intl.DateTimeFormat('en-US', {
timeZone: 'America/New_York',
dateStyle: 'full',
timeStyle: 'long'
});
console.log(fmt.format(now));
// "Monday, March 16, 2026 at 6:30:00 AM EDT"
যেসব দেশ DST পালন করে না
Many countries near the equator and several others do not observe DST, making their offsets constant year-round:
- জাপান (UTC+9), চীন (UTC+8), ভারত (UTC+5:30)
- আফ্রিকার অধিকাংশ, দক্ষিণ-পূর্ব এশিয়া এবং মধ্যপ্রাচ্য
- Arizona (US), Hawaii (US) — state-level exceptions within DST countries
Common timezone pitfalls in code
- টাইমজোন ছাড়া তারিখ পার্স করা — JavaScript-এ
new Date("2026-03-16")UTC মধ্যরাত হিসেবে পার্স হয়, কিন্তুnew Date("03/16/2026")স্থানীয় মধ্যরাত হিসেবে পার্স হয়। সর্বদা টাইমজোন স্পষ্টভাবে উল্লেখ করুন। - ডেটাবেসে স্থানীয় সময় সংরক্ষণ — সর্বদা UTC সংরক্ষণ করুন, আউটপুটে রূপান্তর করুন।
- DST সীমানা জুড়ে টাইমস্ট্যাম্প তুলনা — সর্বদা প্রথমে UTC-তে রূপান্তর করুন।
- পুনরাবৃত্তিমূলক ইভেন্ট নির্ধারণ — অফসেটের পরিবর্তে IANA নাম ব্যবহার করুন, যাতে ভবিষ্যতের DST পরিবর্তন স্বয়ংক্রিয়ভাবে পরিচালিত হয়।
// DANGER: Different parsing behavior!
new Date("2026-03-16").toISOString();
// "2026-03-16T00:00:00.000Z" — UTC midnight ✓
new Date("03/16/2026").toISOString();
// "2026-03-16T05:00:00.000Z" — local midnight in UTC-5 !
// SAFE: always append time and Z for UTC
new Date("2026-03-16T00:00:00Z").toISOString();
// "2026-03-16T00:00:00.000Z" ✓
টাইমস্ট্যাম্প ফরম্যাটের ব্যাখ্যা
Multiple standards define how timestamps are written as human-readable strings. Choosing the right format depends on your use case.
| ফরম্যাট | উদাহরণ | Best Used For |
|---|---|---|
| ISO 8601 প্রস্তাবিত | 2026-03-16T10:30:00.000Z |
API, ডেটাবেস, লগ ফাইল, JSON পেলোড |
| RFC 3339 | 2026-03-16T10:30:00+00:00 |
ইন্টারনেট প্রোটোকল, ATOM ফিড — ISO 8601-এর একটি কঠোর প্রোফাইল |
| RFC 2616 (HTTP) | Mon, 16 Mar 2026 10:30:00 GMT |
HTTP হেডার (Last-Modified, Expires, Cookie) |
| Unix (সেকেন্ড) | 1773835800 |
সংরক্ষণ, তুলনা, গাণিতিক হিসাব — সবচেয়ে ছোট উপস্থাপনা |
| Unix (মিলিসেকেন্ড) | 1773835800000 |
JavaScript, Java, সেকেন্ডের নিচের নির্ভুলতা |
| জুলিয়ান ডেট | 2461110.9375 |
Astronomy, scientific computing — days since Jan 1, 4713 BC |
ISO 8601 গভীরে
ISO 8601 is the international standard for date/time representation. Key components:
2026 - 03 - 16 T 10 : 30 : 00 . 000 Z
Year Month Day Hr Min Sec Ms UTC
With offset:
2026-03-16T10:30:00.000+07:00 (UTC+7)
2026-03-16T10:30:00.000-05:00 (UTC-5)
Date only:
2026-03-16
Week notation:
2026-W12-1 (Year-Week-Weekday)
জুলিয়ান ডেট গণনা
The Julian Date (JD) is a continuous count of days since the beginning of the Julian Period (January 1, 4713 BC). The formula from a Unix timestamp (milliseconds) is:
// Julian Date from Unix milliseconds
julianDate = (unixMs / 86400000) + 2440587.5;
// Example: Jan 1, 1970 00:00:00 UTC
// (0 / 86400000) + 2440587.5 = 2440587.5
// JavaScript
const jd = (Date.now() / 86400000) + 2440587.5;
সাধারণ টাইমস্ট্যাম্প অপারেশন
Because timestamps are just numbers, arithmetic is straightforward. Here are the most common operations:
Add / Subtract time
const now = Date.now(); // ms
// Constants (in milliseconds)
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
const WEEK = 7 * DAY;
// Add 30 days
const in30Days = now + (30 * DAY);
// Subtract 2 hours
const twoHoursAgo = now - (2 * HOUR);
// Add 1 year (approximate — use date lib for exact)
const inOneYear = now + (365.25 * DAY);
30 * DAY is always exactly 30 days in UTC. However, if you need "1 calendar month from now," use a date library (date-fns, Luxon, Day.js) because months have varying lengths.Compare timestamps
const ts1 = 1700000000000;
const ts2 = 1773835800000;
// Is ts1 before ts2?
ts1 < ts2; // true
// Difference in days
const diffDays = (ts2 - ts1) / (1000 * 60 * 60 * 24);
// Is a timestamp in the past?
const isExpired = ts1 < Date.now();
// Sort array of timestamps (ascending)
const sorted = [ts2, ts1, 1000000000000].sort((a, b) => a - b);
তারিখ গাণিতিক হিসাব — দিন/সপ্তাহ/মাসের শুরু ও শেষ
// Start of today (UTC midnight)
const now = new Date();
const startOfDay = new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate())
).getTime();
// Start of this month
const startOfMonth = new Date(
Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1)
).getTime();
// End of today (last ms)
const endOfDay = startOfDay + (24 * 60 * 60 * 1000) - 1;
Format relative time ("2 hours ago")
function relativeTime(ms) {
const diff = ms - Date.now();
const abs = Math.abs(diff);
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
if (abs < 60000) return rtf.format(Math.round(diff/1000), 'second');
if (abs < 3600000) return rtf.format(Math.round(diff/60000), 'minute');
if (abs < 86400000) return rtf.format(Math.round(diff/3600000), 'hour');
return rtf.format(Math.round(diff/86400000), 'day');
}
relativeTime(Date.now() - 7200000); // "2 hours ago"
relativeTime(Date.now() + 86400000); // "tomorrow"
ভাষার দ্রুত রেফারেন্স
৩০+ প্রোগ্রামিং ভাষায় UNIX এপক থেকে মিলিসেকেন্ড হিসেবে বর্তমান সময় পাওয়ার উপায়।
| ভাষা | Code | একক |
|---|---|---|
| JavaScript | Date.now() | ms |
| TypeScript | Date.now() | ms |
| Java | System.currentTimeMillis() | ms |
| Kotlin | System.currentTimeMillis() | ms |
| Python | int(time.time() * 1000) | ms (from s) |
| C# | DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() | ms |
| Go | time.Now().UnixMilli() | ms |
| Rust | SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() | ms |
| PHP | round(microtime(true) * 1000) | ms (from s) |
| Ruby | Time.now.to_i * 1000 | ms (from s) |
| Swift | Int(Date().timeIntervalSince1970 * 1000) | ms |
| Objective-C | [[NSDate date] timeIntervalSince1970] * 1000 | ms |
| C (POSIX) | clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec*1000 + ts.tv_nsec/1e6 | ms |
| C++ | chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count() | ms |
| Scala | System.currentTimeMillis() | ms |
| Groovy | System.currentTimeMillis() | ms |
| Perl | int(time() * 1000) | ms (approx) |
| Lua | os.time() * 1000 | ms (approx) |
| R | as.numeric(Sys.time()) * 1000 | ms |
| MATLAB | posixtime(datetime('now','TimeZone','UTC')) * 1000 | ms |
| Bash / Shell | date +%s%3N | ms |
| PowerShell | [DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds() | ms |
| SQL (PostgreSQL) | EXTRACT(EPOCH FROM NOW()) * 1000 | ms |
| SQL (MySQL) | UNIX_TIMESTAMP(NOW(3)) * 1000 | ms |
| SQL (SQLite) | strftime('%s','now') * 1000 | ms |
| Dart / Flutter | DateTime.now().millisecondsSinceEpoch | ms |
| Haskell | round . (* 1000) <$> getPOSIXTime | ms |
| Elixir | System.system_time(:millisecond) | ms |
| Erlang | erlang:system_time(millisecond) | ms |
| Clojure | (System/currentTimeMillis) | ms |
| F# | DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() | ms |
| Julia | round(Int, time() * 1000) | ms |
| Nim | getTime().toUnix() * 1000 | ms |
| Crystal | Time.utc.to_unix_ms | ms |
| Zig | std.time.milliTimestamp() | ms |
শীর্ষ ভাষাগুলির জন্য বিস্তারিত উদাহরণ
import time
from datetime import datetime, timezone
# Milliseconds since epoch
ms = int(time.time() * 1000)
print(ms) # e.g. 1773835800123
# Convert ms back to UTC datetime
dt = datetime.fromtimestamp(ms / 1000, tz=timezone.utc)
print(dt.isoformat()) # "2026-03-16T10:30:00.123000+00:00"
package main
import (
"fmt"
"time"
)
func main() {
// Milliseconds (Go 1.17+)
ms := time.Now().UnixMilli()
fmt.Println(ms)
// Convert back to time.Time
t := time.UnixMilli(ms)
fmt.Println(t.UTC().Format(time.RFC3339Nano))
}
using System;
// Milliseconds since epoch
long ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
Console.WriteLine(ms);
// Convert back to DateTimeOffset
var dt = DateTimeOffset.FromUnixTimeMilliseconds(ms);
Console.WriteLine(dt.ToString("o")); // ISO 8601
use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
let ms = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_millis();
println!("{}", ms);
}