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
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

 

 

 

 

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.