تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[كود] اريد كود جافا مضى من الوقت على تاريخ معين
#7
عليكم السلام و رحمة الله و بركاته 
هذا تعديل المشاركة السابقة
[*]يحسب السنوات و الشهور والأيام والساعات والدقائق والثواني بدقة.
[*]يتعامل مع السنة الكبيسة وأطوال الأشهر المختلفة.

PHP كود :
<!DOCTYPE html>
<
html lang="ar">
<
head>
<
meta charset="UTF-8">
<
title>العد التراكمي</title>
<
style>
#countupContainer {
    displayflex;
    gap8px;
    background#f0f0f0;
    padding10px;
    border-radius10px;
    font-familyArialsans-serif;
    justify-contentcenter;
    margin-top20px;
}
.
countBox {
    background#4CAF50;
    color#fff;
    padding10px;
    border-radius6px;
    text-aligncenter;
    min-width50px;
}
</
style>
</
head>
<
body>

<
h2>العد التراكمي</h2>
<
div id="countupContainer"></div>

<
script>
var 
startDate = new Date(202001);

function 
countup() {
    var now = new Date();

    var years now.getFullYear() - startDate.getFullYear();
    var months now.getMonth() - startDate.getMonth();
    var days now.getDate() - startDate.getDate();
    var hours now.getHours() - startDate.getHours();
    var minutes now.getMinutes() - startDate.getMinutes();
    var seconds now.getSeconds() - startDate.getSeconds();

    if(seconds 0){ seconds += 60minutes--; }
    if(minutes 0){ minutes += 60hours--; }
    if(hours 0){ hours += 24days--; }

    if(days 0){
        months--;
        var prevMonth = new Date(now.getFullYear(), now.getMonth(), 0);
        days += prevMonth.getDate();
    }

    if(months 0){ months += 12years--; }

    var container document.getElementById("countupContainer");
    container.innerHTML =
        '<div class="countBox">'+years+'<br>years</div>'+
        '<div class="countBox">'+months+'<br>months</div>'+
        '<div class="countBox">'+days+'<br>days</div>'+
        '<div class="countBox">'+hours+'<br>hours</div>'+
        '<div class="countBox">'+minutes+'<br>minutes</div>'+
        '<div class="countBox">'+seconds+'<br>seconds</div>';

    setTimeout(countup1000);
}

window.onload countup;
</
script>

</
body>
</
html

PHP كود :
<!DOCTYPE html>
<
html lang="en">
<
head>
<
meta charset="UTF-8">
<
title>Cumulative Counter Since 2020</title>

<
style>
* { 
box-sizingborder-boxmargin0padding0; }

body {
  font-familyTahomasans-serif;
  backgroundlinear-gradient(135deg#eef2ff, #f8fafc);
  displayflex;
  justify-contentcenter;
  align-itemscenter;
  min-height100vh;
}

.
wrapper {
  text-aligncenter;
  padding2rem;
}

.
title {
  font-size16px;
  color#666;
  margin-bottom1.5rem;
}

.
grid {
  displaygrid;
  grid-template-columnsrepeat(31fr);
  gap14px;
  max-width480px;
  margin0 auto 14px;
}

.
box {
  background#fff;
  border1px solid #ddd;
  border-radius14px;
  padding1.2rem 0.5rem;
  text-aligncenter;
  transitionall 0.2s;
  cursor: default;
  box-shadow0 4px 12px rgba(0,0,0,0.06);
}

.
box:hover {
  transformtranslateY(-4pxscale(1.03);
  box-shadow0 8px 20px rgba(0,0,0,0.1);
}

.
box .num {
  font-size42px;
  font-weightbold;
  color#222;
  line-height1.1;
}

.
box .lbl {
  font-size14px;
  color#999;
  margin-top8px;
}

/* Highlight seconds */
.box.sec {
  border-color#3b82f6;
  background#eff6ff;
}

.
box.sec .num color#1d4ed8; }
.box.sec .lbl color#3b82f6; }

/* Highlight years */
#b-y {
  background#fef3c7;
  border-color#f59e0b;
}
#b-y .num { color: #b45309; }

/* Animation */
@keyframes pop {
  0%   transformscale(1); }
  50%  transformscale(1.2); }
  100% { transformscale(1); }
}

.
animate {
  animationpop 0.25s ease;
}
</
style>
</
head>

<
body>

<
div class="wrapper">
  <div class="title" id="title"></div>

  <div class="grid">
    <div class="box" id="b-y"><div class="num" id="v-y">00</div><div class="lbl">Years</div></div>
    <div class="box" id="b-mo"><div class="num" id="v-mo">00</div><div class="lbl">Months</div></div>
    <div class="box" id="b-d"><div class="num" id="v-d">00</div><div class="lbl">Days</div></div>
  </div>

  <div class="grid">
    <div class="box" id="b-h"><div class="num" id="v-h">00</div><div class="lbl">Hours</div></div>
    <div class="box" id="b-mi"><div class="num" id="v-mi">00</div><div class="lbl">Minutes</div></div>
    <div class="box sec" id="b-s"><div class="num" id="v-s">00</div><div class="lbl">Seconds</div></div>
  </div>
</
div>

<
script>
const 
start = new Date("2020-01-01T00:00:00");

const 
ids = ['y','mo','d','h','mi','s'];
const 
prev = {};
ids.forEach(=> prev[k] = -1);

function 
diff(se) {
  let y  e.getFullYear() - s.getFullYear();
  let mo e.getMonth()    s.getMonth();
  let d  e.getDate()     s.getDate();
  let h  e.getHours()    s.getHours();
  let mi e.getMinutes()  s.getMinutes();
  let sc e.getSeconds()  s.getSeconds();

  if (sc 0) { sc += 60mi--; }
  if (mi 0) { mi += 60h--; }
  if (h  0) { h  += 24d--; }
  if (d  0) { 
    d += new Date(e.getFullYear(), e.getMonth(), 0).getDate(); 
    mo--; 
  }
  if (mo 0) { mo += 12y--; }

  return { ymodhmissc };
}

function 
tick() {
  const diff(start, new Date());
  const vals = { yt.ymot.modt.dht.hmit.mist.};

  ids.forEach(=> {
    if (vals[k] !== prev[k]) {
      const el document.getElementById('v-' k);

      el.textContent String(vals[k]).padStart(2'0');

      el.classList.remove('animate');
      void el.offsetWidth;
      el.classList.add('animate');

      prev[k] = vals[k];
    }
  });
}

/* Dynamic title */
function updateTitle() {
  const now = new Date();
  document.getElementById("title").textContent =
    "Since January 1, 2020 — " now.toLocaleString();
}

tick();
updateTitle();
setInterval(() => {
  tick();
  updateTitle();
}, 
1000);
</
script>

</
body>
</
html
يمكنك الاستفادة من هذا التعديل ايضاً ..
[صورة مرفقة: 177461173141861.gif]
الرد }}}
تم الشكر بواسطة: nnnjk , nnnjk , nnnjk


الردود في هذا الموضوع
RE: اريد كود جافا مضى من الوقت على تاريخ معين - بواسطة Amir_Alzubidy - 28-03-26, 03:48 AM


التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم