Jump to content




[LUA][Code wanted]Real Time


4 replies to this topic

#1 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 07 October 2012 - 04: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

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 October 2012 - 05: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.

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 07 October 2012 - 05:59 PM

View PostLyqyd, on 07 October 2012 - 05:27 PM, said:

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/>

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 October 2012 - 07:13 PM

That just means you didn't look hard enough. :-)

#5 truhgoj

  • Members
  • 51 posts

Posted 07 October 2012 - 07: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)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users