我不知道如何将这段代码转换为变量。我想将其绑定到语句execute数组中。这是我的代码。我发现此代码可获取当前日期和您的时区。
我尝试了$date = function() {}, echo $date();
,但是没有用。我尝试搜索“将函数转换为PHP”,但所有示例均不起作用。我在这里想念什么?甚至有可能吗?
所以我要执行此操作以将其保存在数据库中。有谁可以帮助我吗。非常感谢您的帮助和时间。
function showclienttime()
{
if(!isset($_COOKIE['GMT_bias']))
{
?>
<script type="text/javascript">
var Cookies = {};
Cookies.create = function (name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else {
var expires = "";
}
document.cookie = name + "=" + value + expires + "; path=/";
this[name] = value;
}
var now = new Date();
Cookies.create("GMT_bias",now.getTimezoneOffset(),1);
window.location = "<?php echo $_SERVER['PHP_SELF'];?>";
</script>
<?php
}
else {
$fct_clientbias = $_COOKIE['GMT_bias'];
}
$fct_servertimedata = gettimeofday();
$fct_servertime = $fct_servertimedata['sec'];
$fct_serverbias = $fct_servertimedata['minuteswest'];
$fct_totalbias = $fct_serverbias - $fct_clientbias;
$fct_totalbias = $fct_totalbias * 60;
$fct_clienttimestamp = $fct_servertime + $fct_totalbias;
$fct_time = time();
$fct_year = strftime("%Y", $fct_clienttimestamp);
$fct_month = strftime("%M", $fct_clienttimestamp);
$fct_day = strftime("%d", $fct_clienttimestamp);
$fct_hour = strftime("%I", $fct_clienttimestamp);
$fct_minute = strftime("%M", $fct_clienttimestamp);
$fct_second = strftime("%S", $fct_clienttimestamp);
$fct_am_pm = strftime("%p", $fct_clienttimestamp);
echo $fct_month."/".$fct_day."/".$fct_year." ".$fct_hour.":".$fct_minute.":".$fct_second." ".$fct_am_pm."";
}
$order_number = random_int(100000000,999999999);
$query2 = "INSERT INTO order_history(register_user_id,order_date,order_number,order_history)
VALUES (:register_user_id,:order_date,:order_number,:order_history)";
$statement2 = $connect->prepare($query2);
$statement2->execute(array(
':register_user_id' => $_SESSION['user_id'],
':order_date' => $date,
':order_history' => $output,
':order_number' => $order_number
));
答案 0 :(得分:1)
受支持的php版本5.3 +
<?php
$date= function() {
return date('Y-m-d');
};
echo $date();
?>