PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Reynier Blanco   ubDate   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: example
Class: ubDate
Add or subtract time intervals from dates
Author: By
Last change: The example was corrected
Date: 15 years ago
Size: 2,539 bytes
 

Contents

Class file image Download
This class allows to model the date giving the possibility to carry out operations like:
 to add or subtract => day, month, year ,hour ,minute, second ,etc<br>
 It's possible to change the language to obtain the days of the week and the months alone for english and spanish at now.<br>
 when he/she wants himself to create an object of the class he/she is passed a chain with the date in a format determined by you.<br>
Ex:<br>
    date = "05/16/2008 15:06:03"<br>
    format = "m/d/Y h:i:s"<br>
 
The possible characters to use in the format are:<br>
Day --- --- <br>
    d Day of the month, 2 digits with leading zeros 01 a 31<br>
    j Day of the month without leading zeros 1 to 31 <br>

Month --- --- <br>
    m Numeric representation of a month, with leading zeros 01 through 12 <br>
    n Numeric representation of a month, without leading zeros 1 through 12<br>
Year --- --- <br>
    Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003 <br>
    y A two digit representation of a year Examples: 99 or 03 <br>
Hour --- --- <br>
    B Swatch Internet time 000 through 999 <br>
    g 12-hour format of an hour without leading zeros 1 through 12 <br>
    G 24-hour format of an hour without leading zeros 0 through 23 <br>
    h 12-hour format of an hour with leading zeros 01 through 12 <br>
    H 24-hour format of an hour with leading zeros 00 through 23 <br>
Minute --- ---<br>
    i Minutes with leading zeros 00 to 59 <br>
Second --- ---<br>
    s Seconds, with leading zeros 00 through 59 <br>
<?php
include_once("ubdate.php");
include_once(
"see.php");

$str = "05/16/2008 15:06:03";
$format = "m/d/Y h:i:s";

See::p("<b>Craendo un objeto ubDate con la fecha y hora actual</b>");
$date = new ubDate($str,$format);
See::p($date->obtain());
See::p($date);

$date->set_format();

See::p("<b>Adicionando 2 días</b>");
$date->add_day(2);
See::p($date->obtain());

See::p("<b>Adicionado -4 días</b>");
$date->add_day(-4);
See::p($date->obtain());

See::p("<b>Adicionando 2 horas</b>");
$date->add_hour(2);
See::p($date->obtain());

See::p("<b>Adicionando 40 min</b>");
$date->add_min(40);
See::p($date->obtain());

See::p("<b>Adicionando 3 meses</b>");
$date->add_month(3);
See::p($date->obtain());

See::p("<b>Adicionando 20 segundos</b>");
$date->add_sec(20);
See::p($date->obtain());

See::p("<b>Adicionando 5 semanas</b>");
$date->add_week(5);
See::p($date->obtain());

See::p("<b>Adicionando 1 año</b>");
$date->add_year(1);
See::p($date->obtain());
?>