Jump to content

Html customised date


Go to solution Solved by redsaurus,

Recommended Posts

Hello,

 

I'm a noob in Html, and i try to display a customised date on my forum.

The goal is to convert the real date of the user into a "RP date".

 

For example, 2 real days = 1 RP week

7 RP week = 1 RP month

10 RP month = 1 RP year

 

The calendar start from the real date named "geonosis". I calculate the difference of days between this date and the actual date, and then I convert this number into RP months, years and weeks.

 

I read some tutorials about date in Html and javascript, and tried to build this script :

<script type="text/javascript">
function galacticdate(){
  	var geonosis = new Date(2015,5,25);
   	var rdate = new Date().toString();
  	var rdiff = rdate.getTime() - geonosis.getTime();
  	var gyear=1;
  	var gmonth=1;
  	var gweek=1;
	var jourconv=1000*60*60*24;
	
  	rdiffjour = Math.ceil(rdiff/jourconv);
  	while (rdiffjour > 140)
  	{
  		gyear = gyear + 1;
  		rdiffjour = rdiffjour - 10*14;
  	}
  	while (rdiffjour > 14)
  	{
  		gmonth = gmonth + 1;
  		rdiffjour = rdiffjour - 14;
  	}
  	while (rdiffjour > 2)
  	{
  		gweek = gweek + 1;
  		rdiffjour = rdiffjour - 2;
  	}
   
	 
  	var galacticdisplay = 'An '+gyear+ ', mois '+gmonth+', semaine '+gweek+' de la Guerre des Clones';
  	document.getElementById("galactictimer").innerHTML = galacticdisplay;
  	return
  
}
</script>

<body onload="galacticdate();">
    
<div id="galactictimer"></div>

However, it doesnot work. Nothing is displayed.

 

someone could help me ? :wub:

Link to comment

I am no expert with Javascript, but that script seems to be just calculating something, not writing anything. You'll need to set up some document.write's or console.log's, that's IF the script is working correctly :P

Link to comment
rdate

should just be

new Date();

not

new Date().toString();

 

Thank you a lot ! It works :)

Now, there is another problem :

 

When I try with 20 April 2015 for the starting date, I should get a difference of days about 35 days (with today, 25 May 2015)

However, I get 6 days only !!!!

var geonosis=new Date(2015,04,20,0,0,0,0);
var rdate=new Date();
var rdiff=rdate.getTime()-geonosis.getTime();

It seems there is a problem here.

When I test, rdiff is 516847066 / 1000*60*60*24 = 5,98 days in place of 35.... :

Link to comment

Hello !

 

rdate is ok, the problem was geonosis. Strangely, date(2015,04,20) gives the 20 May 2015, and date(2015,03,20) gives the 20 April 2015....

So January is 0 and not 1...  stupid trap.... :D

 

Thank you all.

Now, I just must find someone who can convert .ase into .md3 and I will be very happy :teehee:

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...