User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 332,650 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,267 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 4925 | Replies: 3
Reply
Join Date: Aug 2005
Posts: 26
Reputation: aish is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
aish's Avatar
aish aish is offline Offline
Light Poster

Display client's PC Date & Time

  #1  
Sep 17th, 2005
I have a asp.net c# web form, when the page load I want to display client computer date and time.I used DateTime.Now.Date() for this. it works well in the localhost, but after I deployed in the web server it displays web server date and time.how can I display client's computer date and time? :o
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Posts: 175
Reputation: Letscode is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Letscode's Avatar
Letscode Letscode is offline Offline
Junior Poster

Re: Display client's PC Date & Time

  #2  
Sep 21st, 2005
Use a Javascript,
Cuz this runs in the client browser.
Check out this code..

var Days = new Array('Sunday','Monday','Tuesday','Wednesday',
	'Thursday','Friday','Saturday');

var today = new Date();
var Year = takeYear(today);
var Month = leadingZero(today.getMonth()+1);
var DayName = Days[today.getDay()];
var Day = leadingZero(today.getDate());
var Hours = leadingZero(today.getHours());
var Minutes = leadingZero(today.getMinutes());
var Seconds = leadingZero(today.getSeconds());

function takeYear(theDate)
{
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

function leadingZero(nr)
{
	if (nr < 10) nr = "0" + nr;
	return nr;
}




I got it from this URL

Your code is working on the server side ,so thats the reason Y you are getting date on the server.

For you code to work on the client side,You gotta code that in Javascript that runs in the client browser.
Save White Tiger
Reply With Quote  
Join Date: Aug 2005
Posts: 26
Reputation: aish is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
aish's Avatar
aish aish is offline Offline
Light Poster

Re: Display client's PC Date & Time

  #3  
Sep 22nd, 2005
Thanks!.
Reply With Quote  
Join Date: Sep 2005
Location: delhi
Posts: 1
Reputation: amitkr is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
amitkr amitkr is offline Offline
Newbie Poster

Re: Display client's PC Date & Time

  #4  
Sep 28th, 2005
<html>
<head>
<script language="JavaScript">
function showDate()
{
alert("Welcome to Java Script","");
var dt=new Date();
var dd=dt.getDate();
var mm=dt.getMonth()+1;
var yyyy=dt.getYear();
txtDate.value=dd+"/"+mm+"/"+yyyy
txtTime.value=dt.getHours() +":"+ dt.getMinutes()+":"+dt.getSeconds();
}
function close()
{
alert("Good Bye, Waiting to see you again","");
}
</script>
</head>
<body bgcolor="pink" onLoad="showDate();" onUnload="close();">
<center>
<font face="Arial" size=5 color="red">
<b> Current Date and Time </b>
</font>
<br> <br> <br> <br> <br> <br>
Current Date:
<input type=text name=txtDate value="">
<br>
Current Time:
<input type=text name=txtTime value="">
</center>
</body>
</html>
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 3:02 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC