Page 1 of 1
Convert javascript to php
Posted: Tue Apr 22, 2008 1:37 pm
by spookiejr
Hi! I still consider myself a noob in programming, but what I want to do is to convert a script that is on a site I run from Java to php (if it's even possible to get the same function).
The script looks like this
Code: Select all
<script>
function date ()
{
var date=new Date ();
var year=date.getYear (), month=date.getMonth (), day=date.getDate ();
return day+'/'+(month+1)+' Anno '+(year-1994);
}
</script>
I'd really appreciate if someone could help me with this function.
Thanks
Thomas
Re: Convert javascript to php
Posted: Tue Apr 22, 2008 2:47 pm
by andym01480
You are looking for something that will display the date
today's day/month+1/year-1994 22/5/14
date(), strtotime() are good clues of functions to look at
Re: Convert javascript to php
Posted: Tue Apr 22, 2008 2:57 pm
by Weirdan
Make sure you understand that moving date/time related code to server from client will make it use server timezone, whereas previously it used client timezone. You will need to either account for client timezone settings in your code or accept the fact the code will not (in general case) function identically due to the changed environment.
Re: Convert javascript to php
Posted: Wed Apr 23, 2008 4:29 pm
by spookiejr
andym01480: That's the kind of function I'm looking for but instead of the output being "22/5/14" I'd like the output to be "22/4 Anno 14"
What would this code look like? Like I stated previously I concider myself to be a real noob in programming, so any help writing the code would be appreciated.
//Thomas
Re: Convert javascript to php
Posted: Thu Apr 24, 2008 5:00 am
by andym01480
The Javascript was month+1 by the way.
This was intriguing to do. I tried
Code: Select all
$weirddate=strtotime("-23929 months"); //23929 is 1994 years less one month.
echo date("d/m Anno Y",$weirddate);
Which didn't work as it was before 1970!
so this works
Code: Select all
$year=date("Y")-1994;
$date=date("d").'/'.date("m").' Anno '.$year;
echo $date;
Note that it is calculated relative to the server's time, so it will be wrong for users the other side of the world etc.
The big question is why would you want to do something like this????
Re: Convert javascript to php
Posted: Thu Apr 24, 2008 12:52 pm
by spookiejr
Thank you for the help, I'll try the script tonight sometime to se the outcome and thereafter decide if I'm still going to use it or not.. The big reason why I don't want to use Java anymore is probably quite obvious.
The site I'm running is for a medieval society and we have our own timeline and this function is supposed to show the visitor what date it is according to our timeline.
Re: Convert javascript to php
Posted: Thu Apr 24, 2008 1:21 pm
by andym01480
Oh - I thought it was a bizarre doomsday cult
Not sure what the obvious reason for not using Javascript is though! <noscript> tags handle those that have it turned off