2088 posts
Location
South Africa
Posted 07 October 2012 - 05:39 PM
Hey guys does anyone know a code that reads the time of a computer? Not the minecraft computer, computer in real life for real life time.
Thanks
8543 posts
Posted 07 October 2012 - 06:27 PM
You can look around on the forums. There's at least one program that fetches the real time from a web server. There's no other way of getting the real time.
2088 posts
Location
South Africa
Posted 07 October 2012 - 06:59 PM
You can look around on the forums. There's at least one program that fetches the real time from a web server. There's no other way of getting the real time.
Obviously i tried to look, couldnt find anything :D/>/>
8543 posts
Posted 07 October 2012 - 08:13 PM
That just means you didn't
look hard enough. :-)
15 posts
Posted 07 October 2012 - 08:39 PM
You need a webspace with php. On this webspace you put this Code:
<?php
if(empty($_GET)) {
echo time();
}
else{
if(!empty($_GET["timezone"])) {
date_default_timezone_set($_GET["timezone"]);
}
else{
date_default_timezone_set('UTC');
}
if(!empty($_GET["format"])) {
echo date($_GET["format"]);
}
else{
echo date(DATE_RFC822);
}
}
?>
In the config of Computercraft you need to have the http api enabled.
With http api enabled you can receive the current time with
http.get("
http://your-domain/your-file.php?timezone=TIMEZONE&format=FORMAT").readAll()
replace TIMEZONE with your timezone (ECT, GMT, UTC, …)
and FORMAT with pattern you want to fit the time into (for example Y-m-d%20H:i:s gives you something like 2012-10-07 21:27:31 , replace your spaces with %20)