Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PHP:strotime无法从文件获取内容_Javascript_Php_Html - Fatal编程技术网

Javascript PHP:strotime无法从文件获取内容

Javascript PHP:strotime无法从文件获取内容,javascript,php,html,Javascript,Php,Html,您好,我尝试将日期转换为strotime,但我的代码不起作用 time.html-显示当前时间,如2017-03-09 07:11:01 time.html <script type="text/javascript"> function getDateTime() { var now = new Date(); var year = now.getFullYear(); var month = now.ge

您好,我尝试将日期转换为strotime,但我的代码不起作用

time.html-显示当前时间,如2017-03-09 07:11:01

time.html

<script type="text/javascript">
    function getDateTime() {
        var now     = new Date(); 
        var year    = now.getFullYear();
        var month   = now.getMonth()+1; 
        var day     = now.getDate();
        var hour    = now.getHours();
        var minute  = now.getMinutes();
        var second  = now.getSeconds(); 
        if(month.toString().length == 1) {
            var month = '0' + month;
        }
        if(day.toString().length == 1) {
            var day = '0' + day;
        }   
        if(hour.toString().length == 1) {
            var hour = '0' + hour;
        }
        if(minute.toString().length == 1) {
            var minute = '0' + minute;
        }
        if(second.toString().length == 1) {
            var second = '0' + second;
        }   
        var dateTime = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;   
        return dateTime;
    }

    document.write(getDateTime());
</script>

代码是这样工作的:strotime(“2017-03-09 07:11:01”);但是我需要使用文件获取内容以获得实时(当前时间),提前感谢

javascript是客户端的,因此您无法从php获取它,time.html将仅在用户读取时打印日期(将显示用户时间)。如果要用php打印时间,则应使用php函数
date()
,以便获得服务器日期(php是服务器端),例如:

echo "Time: ". date("Y/m/d H:i:s");

注意:
strotime()
是一个检查字符串或将字符串转换为时间格式的函数

不幸的是
文件\u get\u contents
没有JavaScript解释器。您不使用这些函数的原因是什么?为什么要包含JavaScript?@JohnPavek php不显示正确的时间我尝试了,时区对我不起作用。这也不起作用,所以可能会问一个关于php代码的问题。不显示正确的时间日期(),我只需要strotime()
echo "Time: ". date("Y/m/d H:i:s");