Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [js] format zegaru
Forum PHP.pl > Forum > Przedszkole
wojtas666
może ktoś przerobić w podanym fragmencie kodu format zegaru z 12h na 24h? (jeżeli się da oczywiście biggrin.gif )
Kod
<!--

function tick() {
   var hours, minutes, seconds, ap;
   var intHours, intMinutes, intSeconds;  var today;
   today = new Date();
   intDay = today.getDay();
   intDate = today.getDate();
   intMonth = today.getMonth();
   intYear = today.getYear();
   intHours = today.getHours();
   intMinutes = today.getMinutes();
   intSeconds = today.getSeconds();
   timeString = DayNam[intDay]+", "+intDate;
   if (intDate == 1 || intDate == 21 || intDate == 31) {
     timeString= timeString + " ";
   } else if (intDate == 2 || intDate == 22) {
     timeString= timeString + " ";
   } else if (intDate == 3 || intDate == 23) {
     timeString= timeString + " ";
   } else {
     timeString = timeString + " ";
   }
   if (intYear < 2000){
     intYear += 1900;
   }
   timeString = timeString+" "+MnthNam[intMonth]+" "+intYear;
   if (intHours == 0) {
      hours = "12:";
      ap = "am.";
   } else if (intHours < 12) {
      hours = intHours+":";
      ap = "am.";
   } else if (intHours == 12) {
      hours = "12:";
      ap = "pm.";
   } else {
      intHours = intHours - 12
      hours = intHours + ":";
      ap = "pm.";
   }
   if (intMinutes < 10) {
      minutes = "0"+intMinutes;
   } else {
      minutes = intMinutes;
   }
   if (intSeconds < 10) {
      seconds = ":0"+intSeconds;
   } else {
      seconds = ":"+intSeconds;
   }
   timeString = timeString+", "+hours+minutes+" "+ap;
   var clock = (document.all) ? document.all("clock") : document.getElementById("clock");
   clock.innerHTML = timeString;
   window.setTimeout("tick();", 6000);
}

tick();

//-->
jest jeszcze jeden plik do tego js do tego zegara, więc jkaby tu się nie dało to zamieszczę ten drugi winksmiley.jpg
kornel-php
Nikt ci tego raczej nie przerobi, na pewno nie za free... Możemy Cię co najwyżej naprowadzić...

Kod
if (intHours == 0) {
     hours = "12:";
     ap = "am.";
  } else if (intHours < 12) {
     hours = intHours+":";
     ap = "am.";
  } else if (intHours == 12) {
     hours = "12:";
     ap = "pm.";
  } else {
     intHours = intHours - 12
     hours = intHours + ":";
     ap = "pm.";
  }


To chyba gdzieś tutaj...
drPayton
Wywal:
  1. if (intHours == 0) {
  2. hours = "12:";
  3. ap = "am.";
  4. } else if (intHours < 12) {
  5. hours = intHours+":";
  6. ap = "am.";
  7. } else if (intHours == 12) {
  8. hours = "12:";
  9. ap = "pm.";
  10. } else {
  11. intHours = intHours - 12
  12. hours = intHours + ":";
  13. ap = "pm.";
  14. }


Zmień:
  1. timeString = timeString+", "+hours+minutes+" "+ap;

Na:
  1. timeString = timeString+", "+intHours+":"+minutes;
wojtas666
dobra, działa
wielkie dzięki drPayton
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.