Jump to content

[SOLVED] gregorian to unix


XpertWorlock

Recommended Posts

Trying to build a function that changes a gregorian time to unix time.  This function should work, but I am thinking the problem is with the 'GregoriantoJD' function not being able to process $month,$day,$year.  Anyways, if someone could make this work

 

function gtu($gregoriantime)
{
$month = date('m', strtotime($gregoriantime));
$day = date('d', strtotime($gregoriantime)); 
$year = date('Y', strtotime($gregoriantime)); 
$jd = GregorianToJD($month,$day,$year);
$unixtime = jdtounix($jd);
return $unixtime;
};

 

 

 

 

$test = gtu(10/20/2008);

echo $test;  

 

Outputs nothing

 

Link to comment
https://forums.phpfreaks.com/topic/134887-solved-gregorian-to-unix/
Share on other sites

It does in a way, but your way makes it at 5am (Why I don't know?)

 

yours make this

 

1224478800

  10/20/2008 5:00 GMT

 

mine makes this

1224460800

  10/20/2008 0:00 GMT

 

 

Could this have something to do with server settings or something?

Doesn't strtotime have something to do with the client or whatever.

 

I'm from Eastern Canada, so my time is -5 GMT

 

 

 

 

 

 

No I don't think GMT is really needed in this.

 

/*Converts Gregorian month/day/year to unix time*/
function gtu($gregoriantime)
{
$month = date('m', strtotime($gregoriantime));
$day = date('d', strtotime($gregoriantime)); 
$year = date('Y', strtotime($gregoriantime)); 
$jd = GregorianToJD($month,$day,$year);
$unixtime = jdtounix($jd);
return $unixtime;
};


/*Converts unix time to gregorian*/
function utg($unixtime)
{
$julius=unixtojd($unixtime);
$Gregorian=jdtogregorian("$julius");
return $Gregorian; 
};


$starttime = "10/20/2008"; 

echo $starttime."= the date we started with<br>";

$test = gtu("$starttime");

echo $test."= This is the outcome of gregorian to unix<br>";

$test = utg("$test");

echo $test."= This is the outcome of unix to gregorian<br>";

 

 

This outputs the unix time of = "1224460800"  Which is 10/20/2008 0:00 GMT

 

when I change it back to Gregorian it comes up 10/19/2008.

 

I'm digging myself in deeper, but just so everyone knows, there is a point to this.

 

 

So what's the matter with this :

 

function utg($unixtime)
{
$julius=unixtojd($unixtime);
$Gregorian=jdtogregorian("$julius");
return $Gregorian; 
};

 

that it comes up the wrong day?

 

 

Even this :

date('m/d/Y', 1224460800);

 

Which is 10/20/2008, comes up 10/19/2008

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.