:: Forum >> General/Off-topic >>

It's vry urgent - how to use NTP(network time protocol)

hello frnds,
good eveng.pls anyone can help me.
How to use Network Time Protocol in javascript,html program.
nw script is wrkng in my system date. but I want to show my server date.tatz y am asking u?hw to use it NTP.
Ashok.S
Tuesday, February 20, 2007

Your reference to NTP is somewhat misleading. If I am not wrong all you care about is time on server machine not clients.

One easy way to do this is; make all date object at server

This is how I would do in JSP

<%
java.util.SimpleDateFormat rfc822 = new java.util.SimpleDateFormat("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z"Locale.US);
%>
var 
sdate = new Date("<%= rfc822.format(new java.util.Date())%>");
 
Other option is to calculate the offset,

var sdate = new Date("date in RFC822 format"); // server time
var cdate = new Date(); // client time

var offset = sdate.getTime() - cdate.getTime();

and then use this offset to adjust your local time.

Cheers,
Sudhaker
http://thej2ee.com
Sudhaker Raj
Tuesday, February 20, 2007
Thanks and thanks a lot sudhaker.but i dnt want jsp format .
here need only in java script format.
my coding is below.its wrking 5n.but it takes only own system date.
but i want to show the server date only.tatz y am asking ntp.
finaly how to use ntp in my script.pls modify and send me reply.

Ashok.S
Wednesday, February 21, 2007
this is one html file.but this form wil save in one excel file.nw it has to working in system date.but i want to show the server name using ntp.
ryt.


<html>
<head>
<SCRIPT LANGUAGE=JAVASCRIPT>
var currentDate = new Date();
var date1 = currentDate.getDate();
var m = currentDate.getMonth()+1;
var year = currentDate.getYear();
var today = date1+"/"+m+"/"+year;

var filePath = "C:\\ashokCM\\practices\\DailyReports\\DailyReport2007.xls";


var totalRows = 0;
var mon="";



function setDate()
{
f1.txtDate1.value=today;
}


function saveToExcel()
{

var myApp = new ActiveXObject("Excel.Application");
myApp.visible = true;
var xlCellTypeLastCell = 11;

var myWorkbook = myApp.Workbooks.Open(filePath);

var myWorksheet = myWorkbook.Worksheets(m);
myWorksheet.Activate;
objRange = myWorksheet.UsedRange;
objRange.SpecialCells(xlCellTypeLastCell).Activate;
var newRow = 0;
var newRow1 = 0;
var startPos = 0;
var i=0;

//newRow = myApp.ActiveCell.Row + 1;
// newRow1 = newRow1 + 1;
// alert('newRow : '+newRow);
// strNewCell = "A" + newRow;
// alert('strNewCell : '+ strNewCell);
// myApp.Range(strNewCell).Activate;

while(i < f1.elements.length-3){
newRow1 = myApp.ActiveCell.Row + 1;
strNewCell = "A" + newRow1;
myApp.Range(strNewCell).Activate;

//newRow1 = newRow1 + 1;
//strNewCell = "A" + newRow1;

myApp.Range(strNewCell).Activate;
myWorksheet.Cells(newRow1,1).value = f1.elements[i++].value;
myWorksheet.Cells(newRow1,2).value = f1.elements[i++].value;
myWorksheet.Cells(newRow1,3).value = f1.elements[i++].value;
myWorksheet.Cells(newRow1,4).value = f1.elements[i++].value;
myWorksheet.Cells(newRow1,5).value = f1.elements[i++].value;
myWorksheet.Cells(newRow1,6).value = f1.elements[i++].value;
myWorksheet.Cells(newRow1,7).value = f1.elements[i++].value;
}

newRow1 = 0;
myApp.Workbooks.Close;
myApp.Close;
}


function addRowToTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
var iteration = lastRow;
var row = tbl.insertRow(lastRow);

// first cell
var cellFirst = row.insertCell(0);
var first= document.createElement('input');
first.type = 'text';
first.name = 'txtDate' + iteration;
first.id = 'txtDate' + iteration;
first.size = 20;
first.value = today;
cellFirst.appendChild(first);

// second cell
var cellSecond = row.insertCell(1);
var second = document.createElement('input');
second.type = 'text';
second.name = 'txtCaller' + iteration;
second.id = 'txtCaller' + iteration;
second.size = 20;
cellSecond.appendChild(second);

//third cell
var cellThird = row.insertCell(2);
var third = document.createElement('input');
third.type = 'text';
third.name = 'txtProduct' + iteration;
third.id = 'txtProduct' + iteration;
third.size = 20;
cellThird.appendChild(third);

//fourth cell
var cellFourth = row.insertCell(3);
var fourth = document.createElement('input');
fourth.type = 'text';
fourth.name = 'txtNOP' + iteration;
fourth.id = 'txtNOP' + iteration;
fourth.size = 20;
cellFourth.appendChild(fourth);

//fifth cell
var cellFifth = row.insertCell(4);
var fifth = document.createElement('input');
fifth.type = 'text';
fifth.name = 'txtSoltions' + iteration;
fifth.id = 'txtSolutions' + iteration;
fifth.size = 20;
cellFifth.appendChild(fifth);

//sixth cell
var cellSixth = row.insertCell(5);
var sixth = document.createElement('input');
sixth.type = 'text';
sixth.name = 'txtStatus' + iteration;
sixth.id = 'txtStatus' + iteration;
sixth.size = 20;
cellSixth.appendChild(sixth);

//seventh cell
var cellSeventh = row.insertCell(6);
var seventh = document.createElement('input');
seventh .type = 'text';
seventh .name = 'txtRemark' + iteration;
seventh .id = 'txtRemark' + iteration;
seventh .size = 20;
cellSeventh .appendChild(seventh );
totalRows = iteration;

}


function removeRowFromTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}


</SCRIPT>
</head>


<BODY onLoad='setDate();'>
<form name="f1" method="post">
<form action="tableaddrow_nw.html" method="get">
<p>
<td align="center"><b>Daily Report</b></td>
<span id="spanOutput" style="border: 1px solid #000; padding: 3px;">
</span>
</p>
<table border="1" id="tblSample">
<tr>

<th> Date </th>
<th> Caller </th>
<th> Product </th>
<th> Nature Of Problem</th>
<th> Solution </th>
<th> Status </th>
<th> Remarks </th>


<tr>


<td>
<input type="text" name="txtDate1" id="txtDate1" size="20" />
</td>


<td><input type="text" name="txtCaller1" id="txtCaller1" size="20" />
</td>


<td>
<input type="text" name="txtProduct1" id="txtProduct1" size="20" />
</td>

<td>
<input type="text" name="txtNOP1" id="txtNOP1" size="20" />
</td>

<td>
<input type="text" name="txtSolutions1" id="txtSolutions1" size="20" />
</td>

<td>
<input type="text" name="txtStatus1" id="txtStatus1" size="20" />
</td>

<td>
<input type="text" name="txtRemark1" id="txtRemark1" size="20" />
</td>



</tr>
</table>
<p>
<input type="button" value="Add" onclick="addRowToTable();" />
<input type="button" value="Remove" onclick="removeRowFromTable();" />
<input type="button" name=save value="Save" onClick='saveToExcel();'>

</p>
</form>
</body>
</html>
http://jehiah.cz/archive/ntp-for-javascript

http://www.juniper.net/techpubs/software/junos/junos57/swconfig57-getting-started/html/cli-summary-environment10.html
Ashok.S
Wednesday, February 21, 2007
hw to display the server date(only) using NTP.
the above html file is to display the own system date.but i want to server date.
Ashok.S
Wednesday, February 21, 2007
Without having some kind of server side script to report the server date you're lost. This is not possible with only Java Script

Java Script = Client Side Code. So a reference to anything would be local (meaning, not on the server at all)

If you're not able to use any other kind of technology I suggest you look elsewhere as this is NOT an Excel forum but a custom widget written that kind of simulates Excel.
AcidRaZor
Monday, February 26, 2007



This topic is archived.

Back to support forum

Forum search