Datum mit Java

Post Reply
Message
Author
riedel1
Posts: 2
Joined: 16. Aug 1999 19:35
Location: BS
Contact:

Datum mit Java

#1 Post by riedel1 »

Hallo,

wenn ich folgenden Code in mein html Dokument einbaue, erhalte ich folgendes:
"November 12, 21900". Das Jahr ist ja wohl falsch.
Hier mal der code:

<script language="JavaScript"> <!--
today = new Date();
month = today.getMonth() + 1;
months = new Array(12);
months<font size="1"> = "January";
months<font size="2"> = "February";
months<font size="3"> = "March";
months<font size="4"> = "April";
months[5] = "May";
months[6] = "June";
months[7] = "July"
months[8] = "August";
months[9] = "September";
months[10] = "October";
months[11] = "November";
months[12] = "December";
year = today.getYear();
if (year < 100) year = "19" + year;
else year = "2" + year - 100;
document.write(months[month] + " " + today.getDate() + ", " + year);
//--></script>

Tipps?
bye
Riedel -> www.riedelweb.de

Descartes

Re: Datum mit JavaScript

#2 Post by Descartes »

Dein Problem: today.getYear() liefert das Jahr 4-stellig zurück

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
<script language="JavaScript" type="text/javascript">
<!--
v_month = new Array(12);
v_month[<!--no-->0] = "January";
v_month[<!--no-->1] = "February";
v_month[<!--no-->2] = "March";
v_month[<!--no-->3] = "April";
v_month[<!--no-->4] = "May";
v_month[<!--no-->5] = "June";
v_month[<!--no-->6] = "July"
v_month[<!--no-->7] = "August";
v_month[<!--no-->8] = "September";
v_month[<!--no-->9] = "October";
v_month[<!--no-->10] = "November";
v_month[<!--no-->11] = "December";
today = new Date();
document.write(v_month[today.getMonth()] + " " + today.getDate() + ", " + today.getYear());
//--></script>
</font><hr></pre></blockquote>

Descartes

Re: Datum mit Java

#3 Post by Descartes »

Falls Du nur was suchst, um auf einer HTML-Seite das Datum der letzten Änderung einzufügen:

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
<script language="JavaScript" type="text/javascript">
<!--
document.write("Last Modified " + document.lastModified)
// -->
</script>
</font><hr></pre></blockquote>

riedel1
Posts: 2
Joined: 16. Aug 1999 19:35
Location: BS
Contact:

Re: Datum mit Java

#4 Post by riedel1 »

Danke dir, jetzt klappts
bye
Riedel -> www.riedelweb.de

Descartes

Re: Datum mit Java

#5 Post by Descartes »

Falls Du allerdings das ganze mit Java machen möchtest...

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
import java.util.*;
import java.text.*;

public class SimpleDateFormatterTest {
public static void main( String args[] )
{
Calendar cal;
DateFormat format;

// The TimeZone ID is, either an abbreviation such as "PST", a full name such
// as "America/Los_Angeles", or a custom ID such as "GMT-8:00".
// Note that the support of abbreviations is for JDK 1.1.x compatibility only
// and full names should be used.
// cal = new GregorianCalendar( TimeZone.getTimeZone("CET") );
// cal = new GregorianCalendar( TimeZone.getTimeZone("GMT+1:00") );
cal = new GregorianCalendar( TimeZone.getTimeZone("Germany/Berlin") );
cal.setTime( cal.getTime() );

// set DateFormat and use local language settings
format = DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.MEDIUM );
System.out.println( format.format( cal.getTime() ) );

// set DateFormat and use italian language settings
format = DateFormat.getDateTimeInstance( DateFormat.FULL, DateFormat.MEDIUM, Locale.ITALY );
System.out.println( format.format( cal.getTime() ) );
}
}
</font><hr></pre></blockquote>

Post Reply