Unix timestamps and time zones explained

An order placed at 1 a.m. in Dhaka shows up in yesterday’s sales report. An API returns 1790481600 and your app displays a date in January 1970. A user in another country sees a birthday one day early. Every one of these bugs comes from mixing up three things: the moment something happened, the unit it is counted in, and the time zone it is shown in. Keep them separate and date handling becomes predictable.

What Unix time is

Unix time is the number of seconds since 1970-01-01T00:00:00Z (the “epoch”), in UTC. It is a single number for a single moment, the same everywhere on Earth: 1790481600 is 04:00 UTC on 27 September 2026, which is 10:00 in Dhaka and 06:00 in Berlin at the same instant. Leap seconds are ignored — every Unix day is exactly 86,400 seconds — which keeps the arithmetic simple.

Seconds or milliseconds?

Different platforms count in different units, and the numbers look similar enough to confuse:

WhereReturnsExample (same moment)
JavaScript Date.now()milliseconds (integer)1790481600000
Python time.time()seconds (float)1790481600.0
Unix shell date +%s, most APIs, JWT expseconds (integer)1790481600
Java System.currentTimeMillis()milliseconds1790481600000

Quick check: a present-day timestamp in seconds has 10 digits; in milliseconds it has 13. Mixing them produces very recognisable wrong dates:

new Date(1790481600).toISOString()          // "1970-01-21T17:21:21.600Z"  ✗ seconds passed as ms
new Date(1790481600 * 1000).toISOString()   // "2026-09-27T04:00:00.000Z"  ✓

Going the other way — milliseconds passed to a function that expects seconds — lands tens of thousands of years in the future; Python’s datetime.fromtimestamp(1790481600000) simply raises an error. If you see 1970 or an impossible year, check the unit first.

UTC, local time and ISO 8601

UTC is the reference clock with no offset and no daylight saving. Local time is UTC plus the offset of a place. When you write a date as text, use ISO 8601 with an explicit offset, so there is no guessing:

2026-09-27T04:00:00Z         // UTC ("Z" = zero offset)
2026-09-27T10:00:00+06:00    // the same moment, written as Dhaka local time
2026-09-27T10:00:00          // ✗ no offset: which 10 o'clock?

The rule that prevents most bugs: store and transmit UTC (or a Unix timestamp), convert to local time only when displaying. The database, logs and APIs all speak UTC; the user interface translates it into the viewer’s zone at the last moment.

An offset is not a time zone. +06:00 describes one moment’s offset. A zone name like Asia/Dhaka carries the full history of rule changes. For future events in a local zone (a meeting at 10 a.m. next month), store the local time plus the zone name, not just a UTC instant.

Bangladesh time: UTC+6, Asia/Dhaka

Bangladesh Standard Time is UTC+6, and the IANA zone name is Asia/Dhaka. There is no daylight saving today. Bangladesh did try it once: from 19 June 2009 until the end of that year, clocks were moved to UTC+7. That one period is recorded in the time-zone database, so always convert with the zone name rather than a hard-coded +6 if you handle historical data.

Because Dhaka is six hours ahead, everything from 18:00 UTC onwards is already the next day in Bangladesh. A “today’s orders” query that uses UTC midnight will put orders made between midnight and 6 a.m. Dhaka time into the previous day.

Converting in code

// JavaScript
const ts = 1790481600;                 // seconds
const d = new Date(ts * 1000);
d.toISOString();                       // "2026-09-27T04:00:00.000Z"

new Intl.DateTimeFormat("en-GB", {
  timeZone: "Asia/Dhaka", dateStyle: "full", timeStyle: "short",
}).format(d);                          // "Sunday, 27 September 2026 at 10:00"

new Intl.DateTimeFormat("bn-BD", {
  timeZone: "Asia/Dhaka", dateStyle: "full", timeStyle: "short",
}).format(d);                          // "রবিবার, ২৭ সেপ্টেম্বর, ২০২৬ এ ১০:০০ AM"

Math.floor(Date.now() / 1000);         // current Unix time in seconds
# Python
from datetime import datetime, timezone
from zoneinfo import ZoneInfo          # on Windows: pip install tzdata

d = datetime.fromtimestamp(1790481600, tz=timezone.utc)
d.isoformat()                                  # '2026-09-27T04:00:00+00:00'
d.astimezone(ZoneInfo("Asia/Dhaka")).isoformat()   # '2026-09-27T10:00:00+06:00'
int(datetime.now(timezone.utc).timestamp())    # current Unix time in seconds

In Python, always pass a tz. A “naive” datetime without one is silently treated as the server’s local time by .timestamp(), so the same code gives different results on your laptop and on a UTC server.

-- PostgreSQL
SELECT to_timestamp(1790481600);                          -- timestamptz
SELECT to_timestamp(1790481600) AT TIME ZONE 'Asia/Dhaka'; -- 2026-09-27 10:00:00
SELECT extract(epoch FROM now());                         -- current Unix time

Prefer timestamptz over timestamp in PostgreSQL: it stores an absolute moment and converts on output. In MySQL, FROM_UNIXTIME() and UNIX_TIMESTAMP() use the session time zone, so set it explicitly.

The Year 2038 problem

Systems that store Unix time in a signed 32-bit integer can count up to 2,147,483,647 seconds, which is 2038-01-19T03:14:07Z (09:14:07 in Dhaka). One second later the value overflows to −2,147,483,648 and the date jumps back to 13 December 1901. Modern 64-bit systems, JavaScript and Python are safe, but watch for 32-bit INT columns holding timestamps, old embedded devices, and binary file formats with 32-bit time fields. Anything that calculates dates 15+ years ahead — loans, certificates, subscriptions — can hit it much sooner.

Common bugs and fixes

Check a timestamp in seconds. The Unix Timestamp Converter auto-detects seconds, milliseconds, microseconds or nanoseconds and shows the date in UTC, your local time and Dhaka time. Try it now

FAQ

Should I store dates as Unix timestamps or as database date types?

Either works if it is UTC. A native type such as PostgreSQL’s timestamptz is easier to query and read; an integer timestamp is simple to pass between systems. Use 64-bit integers if you choose numbers.

Does Unix time change with daylight saving?

No. Unix time is always UTC-based and never jumps. Only the local-time display changes when a zone switches its clocks.

Why does my Dhaka time show as GMT+6 in some places and +06:00 in others?

They are the same offset written in different styles. Intl output often uses “GMT+6”, while ISO 8601 uses +06:00.

ইউনিক্স টাইমস্ট্যাম্প ও টাইম জোন সহজ ভাষায়

ঢাকায় রাত ১টায় দেওয়া অর্ডার চলে গেল গতকালের সেলস রিপোর্টে। API ফেরত দিল 1790481600, আর আপনার অ্যাপ দেখাল ১৯৭০ সালের জানুয়ারির একটা তারিখ। অন্য দেশের একজন ইউজার জন্মদিন দেখলেন এক দিন আগে। প্রতিটি বাগের মূলে তিনটি জিনিস গুলিয়ে ফেলা: ঘটনাটা ঘটার মুহূর্ত, সেটা কোন এককে গোনা হচ্ছে, আর কোন টাইম জোনে দেখানো হচ্ছে। এই তিনটি আলাদা রাখলেই তারিখ নিয়ে কাজ অনুমানযোগ্য হয়ে যায়।

Unix time কী

Unix time হলো 1970-01-01T00:00:00Z (“epoch”) থেকে এখন পর্যন্ত কত সেকেন্ড গেছে, UTC-তে। এক মুহূর্তের জন্য একটাই সংখ্যা, পৃথিবীর সব জায়গায় একই: 1790481600 মানে ২৭ সেপ্টেম্বর ২০২৬, UTC ভোর ৪টা — ঠিক সেই মুহূর্তে ঢাকায় সকাল ১০টা আর বার্লিনে সকাল ৬টা। Leap second হিসাবে ধরা হয় না — Unix-এর প্রতিটি দিন ঠিক ৮৬,৪০০ সেকেন্ড — তাই হিসাব সহজ থাকে।

সেকেন্ড নাকি মিলিসেকেন্ড?

একেক প্ল্যাটফর্ম একেক এককে গোনে, আর সংখ্যাগুলো দেখতে এত কাছাকাছি যে সহজেই গুলিয়ে যায়:

কোথায়কী ফেরত দেয়উদাহরণ (একই মুহূর্ত)
JavaScript Date.now()মিলিসেকেন্ড (পূর্ণসংখ্যা)1790481600000
Python time.time()সেকেন্ড (float)1790481600.0
Unix shell date +%s, বেশিরভাগ API, JWT expসেকেন্ড (পূর্ণসংখ্যা)1790481600
Java System.currentTimeMillis()মিলিসেকেন্ড1790481600000

চট করে চেনার উপায়: এখনকার সময়ের timestamp সেকেন্ডে হলে ১০ অঙ্কের, মিলিসেকেন্ডে হলে ১৩ অঙ্কের। গুলিয়ে ফেললে ভুল তারিখটাও খুব চেনা চেহারার হয়:

new Date(1790481600).toISOString()          // "1970-01-21T17:21:21.600Z"  ✗ সেকেন্ডকে ms হিসেবে দেওয়া
new Date(1790481600 * 1000).toISOString()   // "2026-09-27T04:00:00.000Z"  ✓

উল্টোটা — যে ফাংশন সেকেন্ড চায় তাকে মিলিসেকেন্ড দেওয়া — তারিখকে হাজার হাজার বছর ভবিষ্যতে নিয়ে যায়; Python-এর datetime.fromtimestamp(1790481600000) সরাসরি এরর দেয়। ১৯৭০ বা অসম্ভব কোনো সাল দেখলে আগে এককটা মিলিয়ে দেখুন।

UTC, স্থানীয় সময় আর ISO 8601

UTC হলো রেফারেন্স ঘড়ি — কোনো offset নেই, daylight saving নেই। স্থানীয় সময় হলো UTC-র সাথে কোনো জায়গার offset যোগ করে পাওয়া সময়। তারিখ টেক্সট হিসেবে লিখতে হলে স্পষ্ট offset-সহ ISO 8601 ব্যবহার করুন, যাতে অনুমানের কিছু না থাকে:

2026-09-27T04:00:00Z         // UTC ("Z" = শূন্য offset)
2026-09-27T10:00:00+06:00    // একই মুহূর্ত, ঢাকার স্থানীয় সময়ে লেখা
2026-09-27T10:00:00          // ✗ offset নেই: কোন জায়গার ১০টা?

যে নিয়মটা বেশিরভাগ বাগ ঠেকায়: সংরক্ষণ ও আদান-প্রদান করুন UTC (বা Unix timestamp) দিয়ে, স্থানীয় সময়ে রূপান্তর করুন শুধু দেখানোর সময়। ডেটাবেস, লগ আর API সবাই UTC-তে কথা বলবে; ইউজার ইন্টারফেস একেবারে শেষ মুহূর্তে সেটাকে দর্শকের টাইম জোনে বদলে দেখাবে।

Offset আর টাইম জোন এক জিনিস নয়। +06:00 শুধু একটি মুহূর্তের offset বোঝায়। Asia/Dhaka-এর মতো জোনের নামে থাকে নিয়ম বদলের পুরো ইতিহাস। স্থানীয় জোনে ভবিষ্যতের কোনো ঘটনার জন্য (যেমন আগামী মাসে সকাল ১০টার মিটিং) শুধু UTC মুহূর্ত নয়, স্থানীয় সময় আর জোনের নাম দুটোই রাখুন।

বাংলাদেশের সময়: UTC+6, Asia/Dhaka

বাংলাদেশ স্ট্যান্ডার্ড টাইম হলো UTC+6, আর IANA জোনের নাম Asia/Dhaka। এখন কোনো daylight saving নেই। তবে বাংলাদেশ একবার এটা চালু করেছিল: ২০০৯ সালের ১৯ জুন থেকে সেই বছরের শেষ পর্যন্ত ঘড়ি ছিল UTC+7-এ। এই সময়টুকু টাইম জোন ডেটাবেসে লেখা আছে, তাই পুরোনো ডেটা নিয়ে কাজ করলে হার্ড-কোড করা +6 নয়, সবসময় জোনের নাম দিয়ে রূপান্তর করুন।

ঢাকা ছয় ঘণ্টা এগিয়ে থাকায় UTC সন্ধ্যা ৬টা (18:00) থেকে বাংলাদেশে পরের দিন শুরু হয়ে যায়। UTC মধ্যরাত ধরে বানানো “আজকের অর্ডার” কুয়েরি ঢাকার সময় রাত ১২টা থেকে ভোর ৬টার মধ্যের অর্ডারগুলোকে আগের দিনে ফেলে দেবে।

কোডে রূপান্তর

// JavaScript
const ts = 1790481600;                 // সেকেন্ড
const d = new Date(ts * 1000);
d.toISOString();                       // "2026-09-27T04:00:00.000Z"

new Intl.DateTimeFormat("en-GB", {
  timeZone: "Asia/Dhaka", dateStyle: "full", timeStyle: "short",
}).format(d);                          // "Sunday, 27 September 2026 at 10:00"

new Intl.DateTimeFormat("bn-BD", {
  timeZone: "Asia/Dhaka", dateStyle: "full", timeStyle: "short",
}).format(d);                          // "রবিবার, ২৭ সেপ্টেম্বর, ২০২৬ এ ১০:০০ AM"

Math.floor(Date.now() / 1000);         // এখনকার Unix time, সেকেন্ডে
# Python
from datetime import datetime, timezone
from zoneinfo import ZoneInfo          # Windows-এ: pip install tzdata

d = datetime.fromtimestamp(1790481600, tz=timezone.utc)
d.isoformat()                                  # '2026-09-27T04:00:00+00:00'
d.astimezone(ZoneInfo("Asia/Dhaka")).isoformat()   # '2026-09-27T10:00:00+06:00'
int(datetime.now(timezone.utc).timestamp())    # এখনকার Unix time, সেকেন্ডে

Python-এ সবসময় tz দিন। জোন ছাড়া “naive” datetime-কে .timestamp() চুপচাপ সার্ভারের স্থানীয় সময় হিসেবে ধরে নেয়, ফলে একই কোড আপনার ল্যাপটপে আর UTC-তে চলা সার্ভারে আলাদা ফল দেয়।

-- PostgreSQL
SELECT to_timestamp(1790481600);                          -- timestamptz
SELECT to_timestamp(1790481600) AT TIME ZONE 'Asia/Dhaka'; -- 2026-09-27 10:00:00
SELECT extract(epoch FROM now());                         -- এখনকার Unix time

PostgreSQL-এ timestamp-এর বদলে timestamptz নিন: এটা একটা নির্দিষ্ট মুহূর্ত রাখে আর আউটপুটের সময় রূপান্তর করে। MySQL-এ FROM_UNIXTIME() ও UNIX_TIMESTAMP() session-এর টাইম জোন ব্যবহার করে, তাই সেটা স্পষ্ট করে সেট করে দিন।

২০৩৮ সালের সমস্যা

যেসব সিস্টেম Unix time রাখে signed 32-bit integer-এ, তারা গুনতে পারে 2,147,483,647 সেকেন্ড পর্যন্ত — অর্থাৎ 2038-01-19T03:14:07Z (ঢাকায় সকাল 09:14:07)। এর এক সেকেন্ড পরে মানটা overflow হয়ে −2,147,483,648 হয়ে যায়, আর তারিখ লাফিয়ে ফেরে ১৯০১ সালের ১৩ ডিসেম্বরে। আধুনিক 64-bit সিস্টেম, JavaScript আর Python নিরাপদ; কিন্তু খেয়াল রাখুন timestamp রাখা 32-bit INT কলাম, পুরোনো embedded ডিভাইস আর 32-bit সময়ের ফিল্ডওয়ালা বাইনারি ফাইল ফরম্যাটের দিকে। যা কিছু ১৫ বছর বা তার বেশি সামনের তারিখ হিসাব করে — লোন, সার্টিফিকেট, সাবস্ক্রিপশন — সেগুলো এই সমস্যায় পড়তে পারে অনেক আগেই।

পরিচিত বাগ ও সমাধান

মুহূর্তেই একটা timestamp যাচাই করুন। ইউনিক্স টাইমস্ট্যাম্প কনভার্টার নিজেই চিনে নেয় সেটা সেকেন্ড, মিলিসেকেন্ড, মাইক্রোসেকেন্ড না ন্যানোসেকেন্ড, আর তারিখ দেখায় UTC, আপনার স্থানীয় সময় ও ঢাকার সময়ে। এখনই চেষ্টা করুন

প্রশ্নোত্তর

তারিখ কি Unix timestamp হিসেবে রাখব, নাকি ডেটাবেসের date টাইপে?

UTC হলে দুটোই চলে। PostgreSQL-এর timestamptz-এর মতো native টাইপে কুয়েরি করা আর পড়া সহজ; integer timestamp এক সিস্টেম থেকে আরেক সিস্টেমে পাঠানো সহজ। সংখ্যা বেছে নিলে 64-bit integer ব্যবহার করুন।

Daylight saving-এ কি Unix time বদলায়?

না। Unix time সবসময় UTC-ভিত্তিক, কখনো লাফ দেয় না। কোনো জোন ঘড়ি বদলালে শুধু স্থানীয় সময়ের প্রদর্শন বদলায়।

ঢাকার সময় কোথাও GMT+6 আর কোথাও +06:00 দেখায় কেন?

একই offset, শুধু লেখার ধরন আলাদা। Intl-এর আউটপুটে প্রায়ই “GMT+6” আসে, আর ISO 8601-এ লেখা হয় +06:00।

Related guides

More free tools