
Show HN: An easy way to convert time - Prefinem
https://epoch.sh/
======
schoen
I can see that this might be useful for interactive human use, but I'm not
sure of the benefit of the API. Most popular programming languages have a
library to do this already without relying on a network service.

Unix command line with GNU date:

date --iso-8601=seconds

date --iso-8601=seconds -u # UTC

date --iso-8601=seconds -d @1234567890 # specified time stamp

date -d 2017-06-29T12:28:57-07:00 +%s # other direction

Python: [https://stackoverflow.com/questions/2150739/iso-time-
iso-860...](https://stackoverflow.com/questions/2150739/iso-time-iso-8601-in-
python)

Using a network API for this kind of conversion function that's already built
into programming languages reminds me of the left-pad controversy. You don't
need to outsource basic programming tasks to third-party libraries, and you
also don't need to outsource them to third-party network services.

~~~
avg_dev
I don't think of it as an API to integrate into your service, but more of an
easy to remember thing like [http://http.cat/503](http://http.cat/503)
[http://http.cat/404](http://http.cat/404) etc.

~~~
jrimbault
How does this exist ? I like it.

------
ldenneau
Does not handle leap seconds:

[https://api.epoch.sh/2016-12-31T23:59:60Z](https://api.epoch.sh/2016-12-31T23:59:60Z)

Edge case, but 2016-12-31T23:59:60Z is a valid UTC time.

~~~
Prefinem
I didn't even know that was possible...

~~~
Klathmon
Welcome to the rabbit hole that is date/time handling.

~~~
Prefinem
Yup. Probably just step lightly out of that one. Already have too many irons
in the fire

------
pcunite
I've been using epochconverter.com for several years. Thank you for the
effort. I like to break things. So, don't worry about this. But, it will not
process 10413795600?

~~~
thieving_magpie
It looks like the max value is 9999999999.

"unix": 9999999999, "utc": "2286-11-20T17:46:39Z"

edit: No, I was very wrong. Adding another 9 seems to work. However, moving up
one to 10000000000 does not.

edit2: Okay I wasn't wrong. It just was changed by the OP very quickly. Which
I guess makes this entire post wrong now. But let the record reflect for a
very brief period in my life I was correct.

~~~
Prefinem
Yup, good catch.

------
mixmastamyk
Fun, but I found this part interesting:

    
    
        ⏵ http https://api.epoch.sh/ 
        HTTP/1.1 200 OK
        ...
        Date: Thu, 29 Jun 2017 21:06:20 GMT
        ...
        
        {
            "utc": "2017-06-29T21:06:19Z"
        }
    
    

One second off. ;)

------
eyelidlessness
It's not clear how it detects which type you've passed, but this is pretty
unexpected:

[https://api.epoch.sh/-100](https://api.epoch.sh/-100)

`{"local":"0099-12-31T16:00:00-08:00","unix":-59011459200,"utc":"0100-01-01T00:00:00Z"}`

This too:

[https://api.epoch.sh/8675309](https://api.epoch.sh/8675309)

`{"local":"8675-11-04T16:00:00-08:00","unix":211615977600,"utc":"8675-11-05T00:00:00Z"}`

~~~
Prefinem
This should be fixed now. As others pointed out, had some bad validation

~~~
eyelidlessness
Why is `-100` invalid?

~~~
Prefinem
You know, I have no idea why I even checked for < 0 since it's seconds
backwards since epoch. Just a mental snag I guess

------
dkharrat
It would also be useful to provide a way to convert the other way around (from
a date to epoch).

I actually built a similar tool a while ago:
[http://timeconv.io/](http://timeconv.io/) that's similar to yours :) The goal
is to provide a set of useful time/date utilities.

~~~
Prefinem
It does

[https://epoch.sh/2017-06-29T20:57:08Z](https://epoch.sh/2017-06-29T20:57:08Z)

------
avg_dev
Neat site. How does it know my local time?

~~~
edpichler
Getting of your browser?

~~~
avg_dev
Yes - but how? I looked at the HTTP headers I was sending and none of them
contained the time zone.

~~~
hakanito
Open your console and type `new Date()`. In JS every date is local time by
default

~~~
avg_dev
Sure, but there is no JS on the page, and curling
[https://api.epoch.sh](https://api.epoch.sh) gives the same result.

------
jaytaylor
@Prefinem Do you plan to release the site source code?

I like it, a cool and useful project for sure.

~~~
Prefinem
I could. It’s just a simple Lambda function.

I will try and do so tomorrow.

------
dwrowe
Doesn't seem to like any Unix timestamps less than 10 characters long?

~~~
Prefinem
Fixed. Silly me

