تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[كود] اريد كود جافا مضى من الوقت على تاريخ معين
#1
السلام عليكم
اريد من الاخوه اﻷعزاء كود جافا مضى من التاريخ الفلاني كذا سنه وكذا شهر وكذا يوم وكذا ساعه وكذا دقيقه وكذا ثانيه
ويكون العدد بالثواني المتحركه ان امكن ذلك
الرد }}}
تم الشكر بواسطة:
#2
(27-03-26, 03:53 PM)nnnjk كتب :
السلام عليكم
اريد من الاخوه اﻷعزاء كود جافا مضى من التاريخ الفلاني كذا سنه وكذا شهر وكذا يوم وكذا ساعه وكذا دقيقه وكذا ثانيه
ويكون العدد بالثواني المتحركه ان امكن ذلك

PHP كود :
<!DOCTYPE html>
<
html lang="ar">
<
head>
<
meta charset="UTF-8">
<
title>حساب الفرق بين تاريخين</title>
</
head>
<
body>

<
h2 id="result"></h2>

<
script>
// التاريخ الذي تريد الحساب منه
let startDate = new Date("2020-01-01 00:00:00");
// التاريخ الذي تريد الحساب منه
  
// تحديث كل ثانية
setInterval(function() {
    let now = new Date();

    let diff now startDate// الفرق بالملي ثانية

    let seconds Math.floor(diff 1000);
    let minutes Math.floor(seconds 60);
    let hours   Math.floor(minutes 60);
    let days    Math.floor(hours 24);

    // حساب السنوات والشهور بشكل تقريبي
    let years  Math.floor(days 365);
    let months Math.floor((days 365) / 30);
    let remainingDays = (days 365) % 30;

    let remainingHours hours 24;
    let remainingMinutes minutes 60;
    let remainingSeconds seconds 60;

document.getElementById("result").innerHTML =
    "سنة " years "، " +
    "شهر " months "، " +
    "يوم " remainingDays "، " +
    "ساعة " remainingHours "، " +
    "دقيقة " remainingMinutes "، " +
    "ثانية " remainingSeconds;
}, 
1000);
</
script>

</
body>
</
html
[صورة مرفقة: 177461173141861.gif]
الرد }}}
تم الشكر بواسطة: nnnjk , nnnjk
#3
تسلم
ركبت الكود وعمل بنجاح
الرد }}}
تم الشكر بواسطة:
#4
مع الملاحظه
الكود ليس دقيق
عدد ايام السنه 365 يوم قسمته على 30 والشهر قد يكون 31 يوم او 30 يوم او 28 يوم
الرد }}}
تم الشكر بواسطة: Amir_Alzubidy
#5
(27-03-26, 07:16 PM)nnnjk كتب : مع الملاحظه
الكود ليس دقيق
عدد ايام السنه 365 يوم قسمته على 30 والشهر قد يكون 31 يوم او 30 يوم او 28 يوم

PHP كود :
<script>
// التاريخ الذي تريد الحساب منه
let startDate = new Date("2020-01-01 00:00:00");

// حساب الفرق الحقيقي
function diffDate(startend) {
    let y end.getFullYear() - start.getFullYear();
    let m end.getMonth() - start.getMonth();
    let d end.getDate() - start.getDate();
    let h end.getHours() - start.getHours();
    let min end.getMinutes() - start.getMinutes();
    let s end.getSeconds() - start.getSeconds();

    if (0) { += 60min--; }
    if (min 0) { min += 60h--; }
    if (0) { += 24d--; }

    if (0) {
        let prevMonth = new Date(end.getFullYear(), end.getMonth(), 0);
        d += prevMonth.getDate();
        m--;
    }

    if (0) {
        m += 12;
        y--;
    }

    return { ymdhmin};
}

// تحديث كل ثانية
setInterval(function() {
    let now = new Date();
    let t diffDate(startDatenow);

    document.getElementById("result").innerHTML =
        "سنة " t."، " +
        "شهر " t."، " +
        "يوم " t."، " +
        "ساعة " t."، " +
        "دقيقة " t.min "، " +
        "ثانية " t.s;

}, 
1000);

</
script
[صورة مرفقة: 177461173141861.gif]
الرد }}}
تم الشكر بواسطة: nnnjk
#6
يعطيك العافيه
هذا كود يحسب كم الايام والساعات والدقائق والثواني المتحركه
لاكن لايحسب عدد السنوات ولا اعتقد انه يظبط الفارق تماما
PHP كود :
<SCRIPT type="text/javascript">
                    function 
setcountup(theday,themonth,theyear){
                    
da=theday,mo=themonth,yr=theyear
                    
}
    
setcountup($vboptions[onlinecountup_startdate])
                    var 
prefix="$vboptions[onlinecountup_prefix]&nbsp;"
                    
var suffix="$vboptions[onlinecountup_suffix]"
                    
var countupbgcolor='$vboptions[onlinecountup_bgdcolor]'
                    
var opentags='$vboptions[onlinecountup_opentags]'
                    
var closetags='$vboptions[onlinecountup_closetags]'
                    
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
                    var 
crosscount=''
                    
function start_countup(){
                    if (
document.layers)
    
document.countupnsmain.visibility="show"
                    
else if (document.all||document.getElementById)
    
crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
                    countup
()
                    }
                    if (
document.all||document.getElementById)
                    
document.write('<span id="countupie" style="background-color:'+countupbgcolor+'"></span>')

    
window.onload=start_countup
                    
function countup(){
                    var 
today=new Date()
                    var 
todayy=today.getYear()
                    if (
todayy 1000)
                    
todayy+=1900
                    
var todaym=today.getMonth()
                    var 
todayd=today.getDate()
                    var 
todayh=today.getHours()
                    var 
todaymin=today.getMinutes()
                    var 
todaysec=today.getSeconds()
                    var 
todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
                    paststring
=montharray[mo-1]+" "+da+", "+yr
                    dd
=Date.parse(todaystring)-Date.parse(paststring)
                    
dday=Math.floor(dd/(60*60*1000*24)*1)
                    
dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
                    
dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
                    
dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)

                    if (
document.layers){
                    
document.countupnsmain.document.countupnssub.document.write(opentags+prefix+dday$vboptions[onlinecountup_days], "+dhour+$vboptions[onlinecountup_hours], "+dmin+$vboptions[onlinecountup_minutes]$vboptions[onlinecountup_and] "+dsec+$vboptions[onlinecountup_seconds] "+suffix+closetags)
                    
document.countupnsmain.document.countupnssub.document.close()
                    }
                    else if (
document.all||document.getElementById)
                    
crosscount.innerHTML=opentags+prefix+dday$vboptions[onlinecountup_days], "+dhour+$vboptions[onlinecountup_hours], "+dmin+$vboptions[onlinecountup_minutes]$vboptions[onlinecountup_and] "+dsec+$vboptions[onlinecountup_seconds] "+suffix+closetags

    setTimeout
("countup()",1000)
                    }
                    </
SCRIPT

السلام عليكم
الكود الاخير الذي وضعته انت لايطبع اي شي في الصفحة بعد الادراج
الرد }}}
تم الشكر بواسطة: Amir_Alzubidy
#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
#8
احسنت بارك الله فيك كود جميل
الرد }}}
تم الشكر بواسطة:



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


يقوم بقرائة الموضوع: