🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: de.comp.lang.javascript
2 messages
2 total messages Started by =?UTF-8?Q?Peter_ Wed, 17 Jul 2024 22:19
stringify und parse von Date
#180391
Author: =?UTF-8?Q?Peter_
Date: Wed, 17 Jul 2024 22:19
17 lines
483 bytes
Wenn ich mittels folgendem Dreizeiler die Attribute anzeigen möchte wird
nichts ausgegeben:

for (key in new Date()){
	document.write("key: " + key + "<br>"); // kein Feld vorhanden
}

Dagegen wird das Datum beim Hin- und Zurückkonvertieren behalten.

const aaa = JSON.stringify( new Date() )
const bbb = JSON.parse( aaa )
const ccc = JSON.stringify( bbb )

document.write("aaa " + aaa + "<br>");
document.write("ccc " + ccc + "<br>");

Wie funktioniert das bei dem Date()-Objekt?
Re: stringify und parse von Date
#180392
Author: Stefan Reuther
Date: Thu, 18 Jul 2024 18:11
17 lines
464 bytes
Am 17.07.2024 um 22:19 schrieb Peter Müller:
> Dagegen wird das Datum beim Hin- und Zurückkonvertieren behalten.
>
> const aaa = JSON.stringify( new Date() )
> const bbb = JSON.parse( aaa )
> const ccc = JSON.stringify( bbb )
>
> document.write("aaa " + aaa + "<br>");
> document.write("ccc " + ccc + "<br>");
>
> Wie funktioniert das bei dem Date()-Objekt?

Date() hat eine toJSON-Methode, die wird hier aufgerufen.

bbb ist ein String, kein Date.


  Stefan
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads