المشاركات : 94
المواضيع 18
الإنتساب : Aug 2021
السمعة :
2
الشكر: 122
تم شكره 50 مرات في 48 مشاركات
27-03-26, 03:53 PM
(آخر تعديل لهذه المشاركة : 27-03-26, 09:13 PM {2} بواسطة nnnjk.)
السلام عليكم
اريد من الاخوه اﻷعزاء كود جافا مضى من التاريخ الفلاني كذا سنه وكذا شهر وكذا يوم وكذا ساعه وكذا دقيقه وكذا ثانيه
ويكون العدد بالثواني المتحركه ان امكن ذلك
المشاركات : 80
المواضيع 0
الإنتساب : Nov 2014
السمعة :
3
الشكر: 17171
تم شكره 13215 مرات في 909 مشاركات
(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>
المشاركات : 94
المواضيع 18
الإنتساب : Aug 2021
السمعة :
2
الشكر: 122
تم شكره 50 مرات في 48 مشاركات
تسلم
ركبت الكود وعمل بنجاح
المشاركات : 94
المواضيع 18
الإنتساب : Aug 2021
السمعة :
2
الشكر: 122
تم شكره 50 مرات في 48 مشاركات
مع الملاحظه
الكود ليس دقيق
عدد ايام السنه 365 يوم قسمته على 30 والشهر قد يكون 31 يوم او 30 يوم او 28 يوم
المشاركات : 80
المواضيع 0
الإنتساب : Nov 2014
السمعة :
3
الشكر: 17171
تم شكره 13215 مرات في 909 مشاركات
(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(start, end) { 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 (s < 0) { s += 60; min--; } if (min < 0) { min += 60; h--; } if (h < 0) { h += 24; d--; }
if (d < 0) { let prevMonth = new Date(end.getFullYear(), end.getMonth(), 0); d += prevMonth.getDate(); m--; }
if (m < 0) { m += 12; y--; }
return { y, m, d, h, min, s }; }
// تحديث كل ثانية setInterval(function() { let now = new Date(); let t = diffDate(startDate, now);
document.getElementById("result").innerHTML = "سنة " + t.y + "، " + "شهر " + t.m + "، " + "يوم " + t.d + "، " + "ساعة " + t.h + "، " + "دقيقة " + t.min + "، " + "ثانية " + t.s;
}, 1000);
</script>
المشاركات : 94
المواضيع 18
الإنتساب : Aug 2021
السمعة :
2
الشكر: 122
تم شكره 50 مرات في 48 مشاركات
27-03-26, 11:15 PM
(آخر تعديل لهذه المشاركة : 27-03-26, 11:25 PM {2} بواسطة nnnjk.)
يعطيك العافيه
هذا كود يحسب كم الايام والساعات والدقائق والثواني المتحركه
لاكن لايحسب عدد السنوات ولا اعتقد انه يظبط الفارق تماما
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] " 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>
السلام عليكم
الكود الاخير الذي وضعته انت لايطبع اي شي في الصفحة بعد الادراج
المشاركات : 80
المواضيع 0
الإنتساب : Nov 2014
السمعة :
3
الشكر: 17171
تم شكره 13215 مرات في 909 مشاركات
28-03-26, 03:48 AM
(آخر تعديل لهذه المشاركة : 28-03-26, 04:01 AM {2} بواسطة Amir_Alzubidy.)
عليكم السلام و رحمة الله و بركاته
هذا تعديل المشاركة السابقة
[*]يحسب السنوات و الشهور والأيام والساعات والدقائق والثواني بدقة.
[*]يتعامل مع السنة الكبيسة وأطوال الأشهر المختلفة.
PHP كود : <!DOCTYPE html> <html lang="ar"> <head> <meta charset="UTF-8"> <title>العد التراكمي</title> <style> #countupContainer { display: flex; gap: 8px; background: #f0f0f0; padding: 10px; border-radius: 10px; font-family: Arial, sans-serif; justify-content: center; margin-top: 20px; } .countBox { background: #4CAF50; color: #fff; padding: 10px; border-radius: 6px; text-align: center; min-width: 50px; } </style> </head> <body>
<h2>العد التراكمي</h2> <div id="countupContainer"></div>
<script> var startDate = new Date(2020, 0, 1);
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 += 60; minutes--; } if(minutes < 0){ minutes += 60; hours--; } if(hours < 0){ hours += 24; days--; }
if(days < 0){ months--; var prevMonth = new Date(now.getFullYear(), now.getMonth(), 0); days += prevMonth.getDate(); }
if(months < 0){ months += 12; years--; }
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(countup, 1000); }
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-sizing: border-box; margin: 0; padding: 0; }
body { font-family: Tahoma, sans-serif; background: linear-gradient(135deg, #eef2ff, #f8fafc); display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.wrapper { text-align: center; padding: 2rem; }
.title { font-size: 16px; color: #666; margin-bottom: 1.5rem; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; max-width: 480px; margin: 0 auto 14px; }
.box { background: #fff; border: 1px solid #ddd; border-radius: 14px; padding: 1.2rem 0.5rem; text-align: center; transition: all 0.2s; cursor: default; box-shadow: 0 4px 12px rgba(0,0,0,0.06); }
.box:hover { transform: translateY(-4px) scale(1.03); box-shadow: 0 8px 20px rgba(0,0,0,0.1); }
.box .num { font-size: 42px; font-weight: bold; color: #222; line-height: 1.1; }
.box .lbl { font-size: 14px; color: #999; margin-top: 8px; }
/* 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% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }
.animate { animation: pop 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(k => prev[k] = -1);
function diff(s, e) { 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 += 60; mi--; } if (mi < 0) { mi += 60; h--; } if (h < 0) { h += 24; d--; } if (d < 0) { d += new Date(e.getFullYear(), e.getMonth(), 0).getDate(); mo--; } if (mo < 0) { mo += 12; y--; }
return { y, mo, d, h, mi, s: sc }; }
function tick() { const t = diff(start, new Date()); const vals = { y: t.y, mo: t.mo, d: t.d, h: t.h, mi: t.mi, s: t.s };
ids.forEach(k => { 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>
يمكنك الاستفادة من هذا التعديل ايضاً ..
المشاركات : 94
المواضيع 18
الإنتساب : Aug 2021
السمعة :
2
الشكر: 122
تم شكره 50 مرات في 48 مشاركات
احسنت بارك الله فيك كود جميل
|