java script date conversion from code written in php
<p>I need this code for a practice and client side.. i practiced it with server side..
How could i write this code in java script.
I got this code from internet. and this is in php.. i wanna same code in java script..
Just for practice..
i am converting this with j query and java script code , with java script function. but lot of error..</p>

<pre><code>  function FormatTime($start,$end)
            {
                // Get time difference and setup arrays
                $difference = $end - $start;
                $periods = array("second", "minute", "hour", "day", "week", "month", "years");
                $lengths = array("60","60","24","7","4.35","12");

                // Past or present
                if ($difference &gt;= 0) 
                {
                    $ending = "ago";
                }
                else
                {
                    $difference = -$difference;
                    $ending = "to go";
                }

                // Figure out difference by looping while less than array length
                // and difference is larger than lengths.
                $arr_len = count($lengths);
                for($j = 0; $j &lt; $arr_len &amp;&amp; $difference &gt;= $lengths[$j]; $j++)
                {
                    $difference /= $lengths[$j];
                }

                // Round up     
                $difference = round($difference);

                // Make plural if needed
                if($difference != 1) 
                {
                    $periods[$j].= "s";
                }

                // Default format
                $text = "$difference $periods[$j] $ending";

                // over 24 hours
                if($j &gt; 2)
                {
                    // future date over a day formate with year
                    if($ending == "to go")
                    {
                        if($j == 3 &amp;&amp; $difference == 1)
                        {
                            $text = "Tomorrow at ". date("g:i a", $timestamp);
                        }
                        else
                        {
                            $text = date("F j, Y \a\\t g:i a", $timestamp);
                        }
                        return $text;
                    }

                    if($j == 3 &amp;&amp; $difference == 1) // Yesterday
                    {
                        $text = "Yesterday at ". date("g:i a", $timestamp);
                    }
                    else if($j == 3) // Less than a week display -- Monday at 5:28pm
                    {
                        $text = date("l \a\\t g:i a", $timestamp);
                    }
                    else if($j &lt; 6 &amp;&amp; !($j == 5 &amp;&amp; $difference == 12)) // Less than a year display -- June 25 at 5:23am
                    {
                        $text = date("F j \a\\t g:i a", $timestamp);
                    }
                    else // if over a year or the same month one year ago -- June 30, 2010 at 5:34pm
                    {
                        $text = date("F j, Y \a\\t g:i a", $timestamp);
                    }
                }

                return $text;
            }
</code></pre>
