You know that your language's clock/time API's are broken and they are not reliable at all.

So you are not allowed to use any built-in API to access system time/date.

But you also know that your language's ability to perform date math, and retaining a date/time value in a variable are correct.

Write a program that prints the current date/time without calling any date/time/clock API's. For example DateTime.Now, GetDate() and similar functions are not allowed.

The answer with most upvotes wins.

In case of a tie, the answer with more precision wins (that is, accurate up to seconds, then milliseconds, then microseconds, and so on).

  • 2
    \$\begingroup\$ In other words, talk to a time server? \$\endgroup\$ – Peter Taylor Mar 10 '14 at 17:21
  • 3
    \$\begingroup\$ Yes, you can do that. One possible solution. \$\endgroup\$ – microbian Mar 10 '14 at 17:23
  • 3
    \$\begingroup\$ Rather unspecific question. I guess the most votes will be gathered by an answer like print(input("Please enter the current time")). \$\endgroup\$ – Howard Mar 10 '14 at 17:32
  • 7
    \$\begingroup\$ My money is on "Load REPL for different language and call its non-broken time API." \$\endgroup\$ – Jonathan Van Matre Mar 10 '14 at 17:46
  • 2
    \$\begingroup\$ @swich that is also not allowed. Because your answer will become unreliable. \$\endgroup\$ – microbian Mar 10 '14 at 19:30

35 Answers 35

1 2


Pure HTML, no Javascript or anything. Less is more.

<iframe src="http://wwp.greenwichmeantime.com/time/scripts/clock-8/runner.php"></iframe>



Python in a linux xterm

import os
print "It is {}:{}:{} GMT on the {}th day of {}".format(

/dev/ptmx/ has its timestamp updated every time the xterm is written to, which includes the command invocation.




import struct
import gettime

if __name__ == '__main__':
    print struct.unpack('i', open('gettime.pyc').read()[4:8])[0], 'seconds after Unix epoch'

The self-import statement compiles it to a .pyc file, which contains the timestamp as the second 4-byte word.

Doesn't work multiple times in a row unless you change the .py file or delete the .pyc file.



def latLong = "http://www.ipligence.com/geolocation".toURL().text =~ /GLatLng\(([^)]*)/
def lat= latLong[0][1].tokenize(",")[0].trim()
def lng = latLong[0][1].tokenize(",")[1].trim()
def xml = "http://www.earthtools.org/timezone/${lat}/${lng}".toURL().text
println new XmlSlurper().parseText(xml).localtime

Get latitude and longitude by IP address, then make a Http request to a time server via the latitude and longitude.


Wolfram Language

WolframAlpha["now", {{"Result", 1}, "Plaintext"}]

> 11:15:35 pm MSK  |  Monday, March 10, 2014
  • 8
    \$\begingroup\$ Isn't "now" a built in function for time? \$\endgroup\$ – Milo Mar 11 '14 at 4:31
  • \$\begingroup\$ @Milo No, it's online query to wolframalpha.com. \$\endgroup\$ – swish Mar 12 '14 at 5:36
1 2

Not the answer you're looking for? Browse other questions tagged or ask your own question.