Welcome Guest, Not a member yet? Register   Sign In
need the number of seconds since....
#6

(This post was last modified: 08-15-2018, 12:38 AM by jreklund.)

T = Time
Z = Zone
So that parsers know where to start looking.

U = Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
This is the same as time(), like you wanted.

Personally I'm using UUIDv4 instead of auto incremented. And storing them as BINARY(16). But you can store them as strings too.
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

if ( ! 
function_exists('UUID_TO_BIN'))
{
    function 
UUID_TO_BIN($uuid) {
        
$uuid hex2bin(str_replace('-','',$uuid));
        return 
$uuid;
    }
}

if ( ! 
function_exists('BIN_TO_UUID'))
{
    function 
BIN_TO_UUID($uuid) {
        if( empty(
$uuid) ) return;
        
$uuid bin2hex($uuid);
        
$uuid substr($uuid08) . '-' substr($uuid84) . '-' substr($uuid124) . '-' substr($uuid164)  . '-' substr($uuid20);
        return 
$uuid;
    }
}


if ( ! 
function_exists('UUIDv4'))
{
    
/**
     * Generates a random UUID using the secure RNG.
     *
     * Returns Version 4 UUID format: xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx where x is
     * any random hex digit and Y is a random choice from 8, 9, a, or b.
     *
     * @return string the UUID
     */
    
function UUIDv4()
    {
        
$bytes random_bytes(16);
        
$bytes[6] = chr((ord($bytes[6]) & 0x0f) | 0x40);
        
$bytes[8] = chr((ord($bytes[8]) & 0x3f) | 0x80);
        
$uuid vsprintf('%s%s-%s-%s-%s-%s%s%s'str_split(bin2hex($bytes), 4));
        return 
$uuid;
    }
}

if ( ! 
function_exists('VALID_UUIDv4'))
{
    function 
VALID_UUIDv4($uuid)
    {
        return 
preg_match('/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i',$uuid);
    }


PHP Code:
$date = new DateTime();
echo 
$date->format("Y-m-d\TH:i:s\Z");
// 2018-08-14T23:53:57Z

$date = new DateTime();
echo 
$date->format("Y-m-d\TH:i:s\Z");
// 20180814T235439Z 

YOU NEED TO INSTALL CALENDAR TO USE THIS FUNCTION
http://php.net/manual/en/book.calendar.php
http://php.net/manual/en/datetime.settime.php
http://php.net/manual/en/function.gregoriantojd.php

This assumes that days are counted like this:
1, 2, 3, 4 ...
NOT
01, 02, 03, 04 ...
PHP Code:
$gregorian DateTime::createFromFormat("D M j Y","Thu Aug 16 2018");
$gregorian->setTime(00);                        
echo 
gregoriantojd$gregorian->format('n'), $gregorian->format('j'), $gregorian->format('Y') ); 
Reply


Messages In This Thread
RE: need the number of seconds since.... - by jreklund - 08-15-2018, 12:20 AM



Theme © iAndrew 2016 - Forum software by © MyBB