Posted 18 August 2014 - 03:50 AM
This is a simple PHP script to fetch time in a wide variety of formats.
The PHP file is hosted at http://www.cctime.cu9.co/cctime.php.
The server it is hosted on should be reliable.
The three main formats are as follows:
Example: http://www.cctime.cu...mat=g:i%A%m/d/Y this outputs something like this –> 2:26 AM 08/18/2014
You can create your own by using the table shown here. Each letter represents a time value.
When you enter the URL, you must enter a format and a offset(Timezone difference from UTC). The offset can be negative or positive.
I have used this on an Apache server running on the same server as the minecraft server. This way you could fetch time locally.
I may replace the offset with timezones and make it adjust for things such as Daylight Savings Time in the future.
Example URLs:
http://www.cctime.cu...=0&format=epoch
Basic:
http://www.cctime.cu...0&format=serial
Custom:
http://www.cctime.cu...mat=g:i%A%m/d/Y
Use and modify this PHP file as you wish.
PHP File:
date_default_timezone_set ("UTC");
//User Defined Variables (UDV)
$offset = $_GET['offset'];
$format = $_GET['format'];
//Checks if UDV's are given
if (isset($offset) == 0){
echo("The offset is not defined.");
echo("\n");
}
if (isset($format) == 0){
echo("The format is not defined.");
}
/*
Time Formats:
Epoch
serial
custom
*/
//Epoch
if ($format == "epoch"){
echo time();
}
//serial
if ($format == "serial"){
$offsetstamp = time() + ($offset * 60 * 60);
$day = date("j", $offsetstamp);
$month = date("n", $offsetstamp);
$year = date("Y", $offsetstamp);
$second = date("s", $offsetstamp);
$meridiem = date("A", $offsetstamp);
$hour24 = date("G", $offsetstamp);
$hour12 = date("g", $offsetstamp);
$minute = date("i", $offsetstamp);
$serialized = "{"."month=".$month.","."day=".$day.","."year=".$year.","."hour12=".$hour12.","."hour24=".$hour24.","."minute=".$minute.","."second=".$second.","."meridiem=".$meridiem.",}";
echo $serialized;
}
//custom
if ($format != "serial"){
if($format != "epoch"){
$offsetstamp = time() + ($offset * 60 * 60);
$output = str_replace("%"," ",$format);
$date = date($output, $offsetstamp);
echo $date;
}
}
?>
The PHP file is hosted at http://www.cctime.cu9.co/cctime.php.
The server it is hosted on should be reliable.
The three main formats are as follows:
- Epoch - Unix Timestamp Example: 1408328148
- Basic - a serialized array of basic time value. Example: {month=8,day=17,year=2014,hour12=8,hour24=20,minute=14,second=05,meridiem=PM,}
- Custom - this allows you to create your own format. Explained below.
Example: http://www.cctime.cu...mat=g:i%A%m/d/Y this outputs something like this –> 2:26 AM 08/18/2014
You can create your own by using the table shown here. Each letter represents a time value.
When you enter the URL, you must enter a format and a offset(Timezone difference from UTC). The offset can be negative or positive.
I have used this on an Apache server running on the same server as the minecraft server. This way you could fetch time locally.
I may replace the offset with timezones and make it adjust for things such as Daylight Savings Time in the future.
Example URLs:
Spoiler
Epoch:http://www.cctime.cu...=0&format=epoch
Basic:
http://www.cctime.cu...0&format=serial
Custom:
http://www.cctime.cu...mat=g:i%A%m/d/Y
Use and modify this PHP file as you wish.
PHP File:
Spoiler
<?phpdate_default_timezone_set ("UTC");
//User Defined Variables (UDV)
$offset = $_GET['offset'];
$format = $_GET['format'];
//Checks if UDV's are given
if (isset($offset) == 0){
echo("The offset is not defined.");
echo("\n");
}
if (isset($format) == 0){
echo("The format is not defined.");
}
/*
Time Formats:
Epoch
serial
custom
*/
//Epoch
if ($format == "epoch"){
echo time();
}
//serial
if ($format == "serial"){
$offsetstamp = time() + ($offset * 60 * 60);
$day = date("j", $offsetstamp);
$month = date("n", $offsetstamp);
$year = date("Y", $offsetstamp);
$second = date("s", $offsetstamp);
$meridiem = date("A", $offsetstamp);
$hour24 = date("G", $offsetstamp);
$hour12 = date("g", $offsetstamp);
$minute = date("i", $offsetstamp);
$serialized = "{"."month=".$month.","."day=".$day.","."year=".$year.","."hour12=".$hour12.","."hour24=".$hour24.","."minute=".$minute.","."second=".$second.","."meridiem=".$meridiem.",}";
echo $serialized;
}
//custom
if ($format != "serial"){
if($format != "epoch"){
$offsetstamp = time() + ($offset * 60 * 60);
$output = str_replace("%"," ",$format);
$date = date($output, $offsetstamp);
echo $date;
}
}
?>