Translating from JavaScript to PHP

Hi guys, I am pretty new to php and javascript in general, but more so to php since i have some small background in java programming.

I am trying to convert this code into php since I need variables which i can only get in php and is proving to difficult to use otherwise except my code be in php as well. The problem is I’m not sure on exactly how to use variables and what classes(?) are available in php, or what time the date function works in for php.

[code][/code]

I tried this, but its probably pretty obvious to someone who knows what they are doing what things I’m doing wrong here. Please help, and thanks =]. Also this is supposed to be a basic converter to change a UNIX time stamp into something readable.

[php]<?php

function timeConverter($UNIX_timestamp)
{
$a = new Date(UNIX_timestamp*1000);

$months = array ( 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec' );

$year = $a.$getFullYear();
$month = $months($a.$getMonth());
$date = $a.$getDate();
$hour = $a.$getHours();
$min = $a.$getMinutes();
$sec = $a.$getSeconds();
$half = 'AM';

if($hour < 12) 
 {
	 
 }
 else
 {
	 $hour = $hour - 12;
	 $half = 'PM';
 }
 
 $time = $date+' '+$month+' '+$year+' '+$hour+':'+$min+':'+$sec+' '+$half;
 return time;

}

?>[/php]

well scratch that. date() in php is amazing, just didn’t realize how to use it until now with a time stamp.

Ended up using this for it:

[php]$timestamp = (place unix timestamp here);

$datetime = date("D-M-d-Y h:i:sa T ", $timestamp);

echo $datetime;
[/php]

Sorry for triple post just fyi in case anyone reads this:

That code prints something like this:

Wed-Jan-11-2012 10:47:25pm MST

Sponsor our Newsletter | Privacy Policy | Terms of Service