[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [PROGRAMMERING] JavaScript-ur - 1000 x Tak!



Thu, 26 May 2005 20:58:27 +0200, Peter Makholm <sslug@sslug> skrev:

"Michael Schmidt" <sslug@sslug> writes:

I javascript kan du instantierer et Date-objekt med antallet af
millisekunder siden 1. januar 1970. Der er 2.208.988.800 sekunder fra
1. januar 1900 til 1. januar 1970 (læs RFC 868).

Tak for info (tager man i "IT" verdnen højde for skudsekunder? - jeg
har  ikke læst RFC'en endnu)

RFC'en tager ikke hensyn til skudsekunder. Hvilket er klart da der angives sekundtal for 1970 og for 1976 og forskellen er delelig med 100.

Men jeg vil gætte på at de fleste i dag vil synkronisere op imod UTC,
som tager hensyn til skudsekunder.

Med perl kan man gøre følgende:

nc sunsite.dk time | perl -ne 'print scalar
localtime(unpack("N",$_)-2208988800)'

Fint, det er da en model af bygge vidre på (hvis jeg kan decifrere perlkoden korrekt ;) )

Eller i PHP:


<?php
    $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
    socket_connect($socket,"sunsite.dk", 37);
    $timestamp = socket_read($socket, 4, PHP_BINARY_READ);

    // PHP's unpack returnerer et array. Snyd den:
    list(,$timestamp) = unpack("N", $timestamp);
   // PHP's fortolkning af 'unsigned long (always 32 bit, big endian
    // byte order)' tillader at ovenstående unpack returnerer et negativt
    // tal. Gør noget:
    $timestamp = $timestamp + 0xFFFFFFFF;

    // timerserver regner med sekund 0 i 1900, vi regner med 1970:
    $timestamp = $timestamp - 2208988800;

    echo strftime("%c", $timestamp);
?>

Jeg ved ikke lige hvad min php har røget. Måske skal du ikke lægge
0xFFFFFFFF til $timestamp.

Det bliver prøvet - uden tvivl. Tusind tak!
Så mangler jeg bare at regne ud hvor ofte og hvordan, hvis det er muligt, jeg nøjes med at opdatere et element, fra serveren på en side uden at genindlæse hele siden.



-- Med venlig hilsen /Zmit/ RLU # 314205


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *