מבקש עזרה בכלי לחישוב זמן. - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

מבקש עזרה בכלי לחישוב זמן.


commander

Recommended Posts

הרכבתי ב-javascript קוד לחישוב זמן, שעות דקות ושניות,

אשר אותו הייתי רוצה בתור אפלקציית C או VB ככלי לשימוש.

הנה קוד ה-javascript, אשמח אם חבר כאן יוכל לשלב זאת.

העניין הוא ליצור מחשבון זמן, לדוגמא 1:22:04 ועוד 00:01:15 יהיה שווה 1:23:19

גללו את הקוד על דף HTML.

בתודה.

-------------------------------------------------------------------------------------------------------------------

<html dir=rtl>

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">

<!--

function addValues (value) {

var myForm = document.timeCalculator;

if(myForm.total_time.value.length > 0){

var the_hours = parseInt(myForm.total_time.value.substring(0,myForm.total_time.value.indexOf(":")));

var the_minutes = parseInt(myForm.total_time.value.substring(myForm.total_time.value.indexOf(":")+1,myForm.total_time.value.lastIndexOf(":")));

var the_seconds = parseInt(myForm.total_time.value.substring(myForm.total_time.value.lastIndexOf(":")+1,myForm.total_time.value.length));

}

else{

var the_hours = 0;

var the_minutes = 0;

var the_seconds = 0;

}

var form_hours = parseFloat(myForm.frm_hours.value);

var form_minutes = parseFloat(myForm.frm_minutes.value);

var form_seconds = parseFloat(myForm.frm_seconds.value);

if (isNaN(form_hours)) {form_hours = 0;}

if (isNaN(form_minutes)) {form_minutes = 0;}

if (isNaN(form_seconds)) {form_seconds = 0;}

myForm.frm_hours.value = form_hours;

myForm.frm_minutes.value = form_minutes;

myForm.frm_seconds.value = form_seconds;

form_seconds = (form_hours * 60 * 60) + (form_minutes * 60) + form_seconds;

form_hours = 0; form_minutes = 0;

while(form_seconds >= 60){form_seconds = form_seconds - 60;form_minutes++;}

while(form_minutes >= 60){form_minutes = form_minutes - 60;form_hours++;}

the_hours = value * form_hours + the_hours;

the_minutes = value * form_minutes + the_minutes;

the_seconds = value * form_seconds + the_seconds;

while(the_seconds >= 60){the_seconds = the_seconds - 60;the_minutes++;}

while(the_minutes >= 60){the_minutes = the_minutes - 60;the_hours++;}

while(the_seconds < 0){the_seconds += 60;the_minutes--;}

while(the_minutes < 0){the_minutes += 60;the_hours--;}

the_seconds = Math.round(the_seconds *10000)/10000;

myForm.total_time.value = "" + the_hours + ":" + the_minutes + ":" + the_seconds;

var tempDecimal = the_hours + (the_minutes / 60) + (the_seconds / 60 / 60);

tempDecimal = Math.round(tempDecimal *10000)/10000;

myForm.total_time_decimal.value = "" + tempDecimal + " שעות";

}

function resetValues(){

var myForm = document.timeCalculator;

myForm.frm_hours.value = "";

myForm.frm_minutes.value = "";

myForm.frm_seconds.value = "";

myForm.total_time.value = "0:0:0";

myForm.total_time_decimal.value = "0 שעות";

}

// -->

</script>

<form name="timeCalculator">

<div align="center"><center><table border="0">

<tr>

<td colspan="3"><font color="#800000">הכנס שעה, דקה ושניה, ניתן להכניס גם בנפרד.</font></td>

</tr>

<tr>

<td align="center">שעות<br>

<input TYPE="text" SIZE="7" NAME="frm_hours"></td>

<td align="center">דקות<br>

<input TYPE="text" NAME="frm_minutes" SIZE="7"></td>

<td align="center">שניות<br>

<input TYPE="text" NAME="frm_seconds" SIZE="7"></td>

</tr>

<tr>

<td colspan="3" align="center"><a href="javascript:addValues(1)">הוסף לחישוב</a>  |

  <a href="javascript:addValues(-1)">הסר מהסכום</a>  |  <a

href="javascript:resetValues();">אפס חישוב</a></td>

</tr>

<tr>

<td colspan="3">סה"כ: <input type="text" name="total_time" size="10" maxlength="10" value="0:0:0" READONLY></td>

</tr>

<tr>

<td colspan="3">דצימלי: <input type="text" name="total_time_decimal" size="15" maxlength="10" value="0 שעות" READONLY></td>

</tr>

</table>

</center></div>

</form>

</html>

-------------------------------------------------------------------------------------------------------------------

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...