Home php教程 PHP源码 PHP和UNIX的时间戳记

PHP和UNIX的时间戳记

Jun 08, 2016 pm 05:30 PM
echo mktime php quot unix

<script>ec(2);</script>

这是一个指南,您将不会有一个独立的效果或文件,本月底指南,但你会-希望-有一个了解的U n ix时间戳,让您一个强大的形式管理你的P H P应用。

注意:
此指南预期读者了解如何MySQL数据库的工作和基本知识的PHP
Unix的时间,或POSIX正时间,是一个系统的描述时间点。它被广泛用于不仅对类Unix操作系统,但在许多其它计算机系统,包括Java编程语言。这是一个编码为协调世界,并有足够的类似线性代表时间的推移,它常常是一个错误。

UNIX的时间被广泛使用的PHP 。它的数额秒之间1970年1月1号00:00:00 ( Unix的时代)和本时间,以最接近的第二位。正如你可以想像,在过去35年,现在相当大的数目!

Unix系统时间的事情之一是处理不同的Windows服务器相比, * nix中的服务器。对Linux服务器的时间戳可以积极或消极的,相当于之前和之后的Unix时代。但是Windows服务器生产-1 ,而不是消极的时间戳,或在PHP 5.1 ,它产生虚假的。

PHP有许多预先确定的职能,利用Unix的时间,职能,我们将使用包括:

  • date()
  • mktime()
  • strtotime()
  • time()
  •  
  • 日期( )可能是最常用的日期功能在PHP中,它可以产生目前的日期或选定的时间在大量的概率。表的所有字符串限定在这里可

    mktime ( )已参数,每个设置时间:第二,分钟,小时,月,日及一年。第七届参数是根据每天节省但是如果此设置单独留PHP将找到的DS小时的本身。 mktime ( )返回时间戳记参数的讲话。

    strtotime ( )转换成一个字符串到一个时间戳,如果不能做到这一点它会返回-1或虚假的。

    时间( )返回当前的时间最接近的第二个作为一个时间戳。

    情景
    你有一个形式,进入数据到MySQL数据库包括日期,在不同的网页你需要回电只是其中之一您的数据库列。

    解决方案:作为Unix的时间每一秒的变化,他们几乎是独一无二的,以便使用,您可以选择某行的时间戳,例如:

    $sql = "SELECT * FROM data WHERE timestamp = " . strtotime("Sunday 3rd August 15:20:36");
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    echo "
    "
    Copy after login
    ;
    print_r($row);
    echo "";
    此脚本进行了查询的数据库表“数据”选择的所有行的时间戳是相同的时间戳记的“星期日8月3日15点二十分36秒。 ”脚本然后显示阵列美元排这是所有的数据检索查询。

    这解决了问题,因为所有的数据只有一列是一个数组美元,连续随时可以输出到该网页。缺点这一解决方案是,时间是一个非常准确的,如果所谓的日期,甚至第二次了它不会选择正确的数据。

    你有一个截止日期为一块的工作,你想知道有多少小时你已经离开。

    解决方案:您可以使用mktime功能,输入日期的截止日期和时间戳记减去这与目前的时间找出多少时间了。
    $day = 1;
    $month = 11;
    $year = 2005;
    $deadline = mktime('', '', '', $month, $day, $year);
    $now = time();
    $age = $deadline - $now;
    $hours = floor($age * 60 * 60);
    $age = $hours * 24;
    echo "Only $age days ($hours hours) left!";
    此脚本使用mktime ( )获得的Unix时间戳2005年十一月一号(新cssreboot截止日期)和时间( )函数获得当前的时间戳记。这两个都是号码,几秒钟内,我们可以阻挡它们。其结果是秒数的差异,所以乘以60给你分,再次60 -小时,并获得2 4天。

    你有时间和你需要显示,作为一个在不同的日期格式。
    echo date("l dS of F Y",$timestamp);
    // Produces something like: Monday 15th of August 2005
     
    echo date("r",$timestamp);
    // the RSS date format (RFC 2822)
    // example: Thu, 21 Dec 2000 16:01:07 +0200
     
    echo date("m.d.y");
    // short-hand date: 03.10.01
    日期显示功能的变化无数的变化,当前的日期和时间戳记时加入的第二个参数是日期格式,而不是现在的一个。如果你想要写的日期功能的如“的”或“ ”的字符,可以显示日期格式必须逃脱的 。完整的表的日期功能是可在这里。

    这样就大功告成了!我希望,如果你遵循了这一指导你学到一些新的PHP的时间,我希望您可以使用这个新的知识在您下次PHP的项目

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

    PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

    7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

    If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

    How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

    Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

    Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

    JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

    How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

    This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

    PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

    A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

    Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

    Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

    What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

    What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

    See all articles