Home PHP Libraries Other libraries A complete PHP time class library
A complete PHP time class library
<?php
class time{
  private $year;//年
  private $month;//月
  private $day;//天
  private $hour;//小时
  private $minute;//分钟
  private $second;//秒
  private $weekday;//星期
  private $longDate;//完整的时间格式
  private $diffTime;//两个时间的差值
  //返回年份 time:时间格式为时间戳  2016-8-27
  function getyear($time="",$type=""){
    if($time==""){
      $time=time();
    }
    if($type==1){
      return $this->year=date("y",$time); //返回两位的年份 16
    }else{
      return $this->year=date("Y",$time); //返回四位的年份 2016
    }
  }
  //返回当前时间的月份 time:时间格式为时间戳 2016-8-27
  function getmonth($time="",$type=""){
    if($time==""){
      $time=time();
    }

A complete example of PHP time class, involving PHP's various operating techniques for obtaining and comparing dates, times, days, etc. It is very simple and practical. Friends who need it can refer to it to facilitate everyone to learn and experience PHP code.

Disclaimer

All resources on this site are contributed by netizens or reprinted by major download sites. Please check the integrity of the software yourself! All resources on this site are for learning reference only. Please do not use them for commercial purposes. Otherwise, you will be responsible for all consequences! If there is any infringement, please contact us to delete it. Contact information: admin@php.cn

Related Article

PHP implements a relatively complete database operation class PHP implements a relatively complete database operation class

27 Dec 2016

This article mainly introduces PHP to implement a relatively complete database operation class, which can implement basic database connections, execute SQL statements, error prompts and other related skills. Friends in need can refer to it.

Complete example of PHP time class Complete example of PHP time class

08 May 2018

This article mainly introduces a complete example of PHP time class, involving PHP operation skills for obtaining and comparing dates, times, days, etc. It is very simple and practical. Friends who need it can refer to it.

(Practical) Complete example of PHP time class (Practical) Complete example of PHP time class

08 Feb 2017

This chapter describes (practical) the details of a complete example of the PHP time class. Friends in need can refer to the following

A complete image upload php class A complete image upload php class

25 Jul 2016

A complete image upload php class

Basic usage of phpexcel class library, a complete collection of phpexcel introductory examples Basic usage of phpexcel class library, a complete collection of phpexcel introductory examples

25 Jul 2016

Basic usage of phpexcel class library, a complete collection of phpexcel introductory examples

A complete tutorial on implementing real-time communication using PHP and Swoole A complete tutorial on implementing real-time communication using PHP and Swoole

28 Jun 2023

With the rapid development of Internet and mobile communication technology, real-time communication has attracted more and more attention. Real-time communication can realize instant messaging between users, online audio and video calls, game battles and other functions, bringing more possibilities to Internet applications. This article will introduce how to use PHP and Swoole to achieve real-time communication. Starting from a simple WebSocket application, we will gradually introduce the basic knowledge of Socket programming and the application practice of Swoole. You need to know PHP to read this article

See all articles