• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

[ASP] Get local date/time

Question

8 answers to this question

Recommended Posts

  • 0
Tom    1,190

Dim d_today
d_today=Date
Response.Write d_today[/CODE]

No need for JS.

Share this post


Link to post
Share on other sites
  • 0
+Human.Online    8,429

Isn't that just going to run on the server? He wants client datetime?

Or am I missing something?

Share this post


Link to post
Share on other sites
  • 0
James Rose    38

Correct nik, i need to get the time on the clients computer

Share this post


Link to post
Share on other sites
  • 0
Rohdekill    775

I'm still trying to figure out why anyone would need or want client time.

All db entries should ALWAYS be server date/time.

If you believe you can successfully defend using client time - explain to us how beneficial the db entries are when a client can change the date/time/timezone at will?

Share this post


Link to post
Share on other sites
  • 0
James Rose    38

I have to crwat a time sheetbfor our comoany and our cs reps are all around the country. Their manager wants the users time.

Share this post


Link to post
Share on other sites
  • 0
Rohdekill    775

I would record in server time and add a column to my user table to track time zone adjustments. When displaying reports show server time + hours for time zone adjustment.

I.E. Server is CST zone, one user is in California (-2 time zone) another in New York (+2 time zone). Always record server time.

Else, if anyone caught on to you recording client time, one could clock in, set the workstation clock 8 hours ahead and clock out. You've just recorded that person worked 8 hours when in fact they worked 15 seconds.

Share this post


Link to post
Share on other sites
  • 0
James Rose    38

While your point about the user affecting the local time is correct, i think you over estimate the intel of our cs reps. :)

Because a rep can log in from anywhere the adjustment will be unpractical... but i will take your point to heart.

Share this post


Link to post
Share on other sites
  • 0
Rohdekill    775

What do you mean by "they can log in from anywhere"? Are you saying they are traveling constantly between time zones? If so, what good would it do to record client time?

I'm just trying to figure out your logic, because If I follow your rule:

Employee A signs in in New York and clocks in at 1/31/12 12:00:00, boards a plane, flies to California in 4 hours, boots up the laptop, and sees his clock is now 4 hours ahead so he sets it correctly (which is very common). Logs back in and you record 1/31/12 12:00:05.

According to this, Employee A now worked 5 seconds.

With my way:

same scenario, but server time is CST - first clock in is now 1/31/12 10:00:00. Regardless what the user does to his clock after the flight, the second clock time is 1/31/12 14:00:05. When I show you the times on the screen, I know the user is at a +2 time zone so I display 1/31/12 12:00:00 thru 1/31/12 16:00:05 which means Employee A worked 4 hours, 5 seconds and the times reflect his local time zone.

If they want to go with client time, then they need to be prepared to accept that the numbers may be way off. I would present these as concerns - especially if the reports are used in payroll or efficiency reports.

But to answer your question:


<body>
<form id="form1" runat="server">
<div>
<input id="_USERDATE" name="_USERDATE" type="hidden" />
<script type="text/javascript">
document.getElementById('_USERDATE').value = (new Date()).toLocaleString();
</script>
<asp:Button ID="Button1" runat="server" Text="Get local datetime" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server"></asp:Label>
</div>
</form>
</body>

protected void Button1_Click(object sender, EventArgs e)
{
string dateLocale = Request.Form["_USERDATE"];
DateTime localDate = DateTime.MinValue;
foreach (System.Globalization.CultureInfo ci in System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.AllCultures))
{
if ((ci.CultureTypes & System.Globalization.CultureTypes.NeutralCultures) != System.Globalization.CultureTypes.NeutralCultures && DateTime.TryParse(dateLocale, ci, System.Globalization.DateTimeStyles.None, out localDate))
break;
}
Label1.Text = (localDate != DateTime.MinValue) ? localDate.ToString("G") : "Cannot resolve local date.";
}
[/CODE]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.