justuse.me
TutorialApril 18, 2026

Calculate Unix Timestamp for Scheduling API Requests

How to convert dates to epoch timestamps when building scheduled API calls, cron jobs, and time-based automations.

Calculate Unix Timestamp for Scheduling API Requests

Last week I was building a script to schedule social media posts through an API. The endpoint wanted timestamps in epoch format. I had dates like "2024-02-15 09:00:00" that I needed to convert.

This happens constantly when you're working with APIs. Most scheduling systems use Unix timestamps because they're simple integers that work across timezones and platforms.

What exactly is a Unix timestamp?

It's the number of seconds since January 1, 1970 00:00:00 UTC. That's it.

Right now (as I write this) the timestamp is around 1704067200. Tomorrow it'll be 86400 seconds higher. The API doesn't care about your timezone or date format. It just wants that number.

Why APIs use epoch time for scheduling

I used to wonder why APIs don't just accept "2024-02-15 09:00:00" directly. Three reasons:

No timezone confusion. When you send "09:00:00", is that UTC? PST? The user's local time? With a Unix timestamp, it's always absolute. 1704067200 is the same moment everywhere.

Easy math. Want to schedule something 7 days from now? Add 604800 seconds. Want to check if a timestamp is in the past? Compare two integers. No parsing needed.

Database friendly. Storing and indexing integers is faster than date strings. Queries like "give me all scheduled items between X and Y" are simple range comparisons.

Converting dates to timestamps in different languages

Here's how I do it in the languages I use most:

JavaScript: