<tfoot id='RYYRs'></tfoot>

    <i id='RYYRs'><tr id='RYYRs'><dt id='RYYRs'><q id='RYYRs'><span id='RYYRs'><b id='RYYRs'><form id='RYYRs'><ins id='RYYRs'></ins><ul id='RYYRs'></ul><sub id='RYYRs'></sub></form><legend id='RYYRs'></legend><bdo id='RYYRs'><pre id='RYYRs'><center id='RYYRs'></center></pre></bdo></b><th id='RYYRs'></th></span></q></dt></tr></i><div id='RYYRs'><tfoot id='RYYRs'></tfoot><dl id='RYYRs'><fieldset id='RYYRs'></fieldset></dl></div>

      <small id='RYYRs'></small><noframes id='RYYRs'>

        • <bdo id='RYYRs'></bdo><ul id='RYYRs'></ul>
        <legend id='RYYRs'><style id='RYYRs'><dir id='RYYRs'><q id='RYYRs'></q></dir></style></legend>

        在 Linux 机器上使用 PHP 将 Windows 时间戳转换为日期

        Convert Windows Timestamp to date using PHP on a Linux Box(在 Linux 机器上使用 PHP 将 Windows 时间戳转换为日期)
      1. <tfoot id='tBBA7'></tfoot>
        • <legend id='tBBA7'><style id='tBBA7'><dir id='tBBA7'><q id='tBBA7'></q></dir></style></legend>

          <small id='tBBA7'></small><noframes id='tBBA7'>

                <tbody id='tBBA7'></tbody>
            1. <i id='tBBA7'><tr id='tBBA7'><dt id='tBBA7'><q id='tBBA7'><span id='tBBA7'><b id='tBBA7'><form id='tBBA7'><ins id='tBBA7'></ins><ul id='tBBA7'></ul><sub id='tBBA7'></sub></form><legend id='tBBA7'></legend><bdo id='tBBA7'><pre id='tBBA7'><center id='tBBA7'></center></pre></bdo></b><th id='tBBA7'></th></span></q></dt></tr></i><div id='tBBA7'><tfoot id='tBBA7'></tfoot><dl id='tBBA7'><fieldset id='tBBA7'></fieldset></dl></div>
                <bdo id='tBBA7'></bdo><ul id='tBBA7'></ul>

                  本文介绍了在 Linux 机器上使用 PHP 将 Windows 时间戳转换为日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个运行在 linux 机器上的 Intranet,它通过 PHP 使用 LDAP 对 Windows 机器上的 Active Directory 进行身份验证.

                  I have an intranet running on a linux box, which authenticates against Active Directory on a Windows box, using LDAP through PHP.

                  我可以使用 LDAP 从 AD 检索用户的条目并从 php 数组访问上次登录日期,例如:

                  I can retrieve a user's entry from AD using LDAP and access the last login date from the php array eg:

                  echo $adAccount['lastlogontimestamp'][0]; // returns something like 129802528752492619
                  

                  如果这是一个 Unix 时间戳,我将使用以下 PHP 代码转换为人类可读的日期:

                  If this was a Unix timestamp I would use the following PHP code to convert to a human readable date:

                  date("d-m-Y H:i:s", $lastlogontimestamp);
                  

                  然而,这行不通.有谁知道我如何实现这一点,或者是否可以从 Linux 机器上实现?

                  However, this does not work. Does anyone know how I can achieve this or indeed if it is possible to do so from a Linux box?

                  推荐答案

                  根据 this,您拥有的 Windows 时间戳是自 1601 年 1 月 1 日以来的 100 ns 数.因此,您可以使用以下公式将其转换为 unix 时间戳:

                  According to this, the windows timestamp you have there is the number of 100-ns since Jan 1st 1601. Therefore, you could just convert it to a unix timestamp using the following formula:

                  tUnix = tWindow/(10*1000*1000)-11644473600;
                  

                  您除以 10*1000*1000 转换为自 1601 年 1 月 1 日以来的秒数,然后您将 11644473600 打折,这是 1601 年 1 月和 1970 年 1 月之间的秒数(Unix 时间).

                  You divide by 10*1000*1000 to convert to seconds since Jan 1st 1601 and then you discount 11644473600 which is the number of seconds between Jan 1601 and Jan 1970 (unix time).

                  所以在 PHP 中:

                  date("d-m-Y H:i:s", $lastlogontimestamp/10000000-11644473600);
                  

                  有趣的是,我得到的偏移量与 Baba 不同.我用 Java 得到了我的:

                  Interestingly, I got a different offset than Baba. I got mine with Java:

                  Calendar date1 = Calendar.getInstance(); date1.set(1601, 1, 1);
                  Calendar date2 = Calendar.getInstance(); date2.set(1970, 1, 1);
                  long dt = date2.getTimeInMillis() - date1.getTimeInMillis();
                  System.out.println(String.format("%f", dt / 1000.0)); // prints "11644473600.000000"
                  

                  根据此 SO:将 Unix/Linux 时间转换为 Windows 时间的方法我的偏移量是正确的.

                  According to this SO: Ways to Convert Unix/Linux time to Windows time my offset is correct.

                  这篇关于在 Linux 机器上使用 PHP 将 Windows 时间戳转换为日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Joomla 2.5 much faster than Joomla 1.5 Querywise(Joomla 2.5 比 Joomla 1.5 Querywise 快得多吗)
                  How to share Joomla login session from one joomla website to one ASP.Net MVC website(如何将 Joomla 登录会话从一个 joomla 网站共享到一个 ASP.Net MVC 网站)
                  htaccess redirect root to subdirectory but allow index.php in root AND query strings to function(htaccess 将根重定向到子目录,但允许根和查询字符串中的 index.php 起作用)
                  Joomla include database functions(Joomla 包含数据库功能)
                  nl2br() not working when displaying SQL results(显示 SQL 结果时 nl2br() 不起作用)
                  Joomla 2.5 JFactory::getSession(); seems to be caching in firefox(Joomla 2.5 JFactory::getSession();似乎在 Firefox 中缓存)

                    1. <tfoot id='Yrtaq'></tfoot>
                      • <i id='Yrtaq'><tr id='Yrtaq'><dt id='Yrtaq'><q id='Yrtaq'><span id='Yrtaq'><b id='Yrtaq'><form id='Yrtaq'><ins id='Yrtaq'></ins><ul id='Yrtaq'></ul><sub id='Yrtaq'></sub></form><legend id='Yrtaq'></legend><bdo id='Yrtaq'><pre id='Yrtaq'><center id='Yrtaq'></center></pre></bdo></b><th id='Yrtaq'></th></span></q></dt></tr></i><div id='Yrtaq'><tfoot id='Yrtaq'></tfoot><dl id='Yrtaq'><fieldset id='Yrtaq'></fieldset></dl></div>

                          <legend id='Yrtaq'><style id='Yrtaq'><dir id='Yrtaq'><q id='Yrtaq'></q></dir></style></legend>

                            <tbody id='Yrtaq'></tbody>

                          <small id='Yrtaq'></small><noframes id='Yrtaq'>

                            <bdo id='Yrtaq'></bdo><ul id='Yrtaq'></ul>