473,839 Members | 1,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing client date and time

Hi!

I would like to get the clients date and time (his system time) and
store it somewhere so I can use it in my code later. (insert it to
database!).
Any ideas
Zvonko
Aug 30 '05 #1
8 3378
"Zvonko" <zv****@velepro met.hr> wrote in message
news:df******** **@ss405.t-com.hr...
Hi!

I would like to get the clients date and time (his system time) and
store it somewhere so I can use it in my code later. (insert it to
database!).
Any ideas
Zvonko


One possible approach which requires that JavaScript be enabled:

<html>
<head>
<title>page1.ht m</title>
<body>
<form action="page2.h tm" method="get" name="form1">
<input type="hidden" name="When" size="10" value="yyyymmdd hhnnss">
</form>
<script type="text/javascript">
var when = new Date();
var form = document.form1;
form.When.value = when.getFullYea r();;
form.When.value += (100+(when.getM onth()+1)+"").s ubstr(1);
form.When.value += (100+(when.getD ate())+"").subs tr(1);
form.When.value += (100+(when.getH ours())+"").sub str(1);
form.When.value += (100+(when.getM inutes())+"").s ubstr(1);
form.When.value += (100+(when.getS econds())+"").s ubstr(1);
alert(form.When .value + "\n" + "yyyymmddhhnnss ");
form.submit();
</script>
</body>
</html>
Aug 30 '05 #2
Zvonko wrote on 30 aug 2005 in comp.lang.javas cript:
I would like to get the clients date and time (his system time) and
store it somewhere so I can use it in my code later. (insert it to
database!).
Any ideas


var myStore = new Date()

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Aug 30 '05 #3
JRS: In article <xL************ ********@comcas t.com>, dated Tue, 30 Aug
2005 08:36:13, seen in news:comp.lang. javascript, McKirahan
<Ne**@McKirahan .com> posted :
"Zvonko" <zv****@velepro met.hr> wrote in message
news:df******* ***@ss405.t-com.hr...
I would like to get the clients date and time (his system time) and
store it somewhere so I can use it in my code later. (insert it to
database!).


You should consider storing also the client offset from GMT. However,
if the database is not on the client computer, you should consider using
the server date and time, for reliability.

var when = new Date();
var form = document.form1;
form.When.value = when.getFullYea r();;
form.When.value += (100+(when.getM onth()+1)+"").s ubstr(1);
form.When.value += (100+(when.getD ate())+"").subs tr(1);
form.When.value += (100+(when.getH ours())+"").sub str(1);
form.When.value += (100+(when.getM inutes())+"").s ubstr(1);
form.When.value += (100+(when.getS econds())+"").s ubstr(1);
alert(form.When .value + "\n" + "yyyymmddhhnnss ");
form.submit();


You have been told that an efficient way of making a small integer into
a two-digit integer in VBScript is to add 100 and use the end of the
string. Do not assume that the same holds in javascript; it is
relatively inefficient there.

Do not repeat code; Leading Zero should be a function, unless you can
show that coding it in-line is significantly quicker in context.

It cannot be efficient to evaluate the location of form.When.value
several times; remove all form.When.value += and change the preceding
semicolons to pluses.

There is no need, however, to do any string manipulation; arithmetic
will be quicker, as has been indicated in the MS VBScript newsgroup.

with (when) Ans =
((((getFullYear ()*100+getMonth ()+1)*100+getDa te())
*100+getHours() )*100+getMinute s())*100+getSec onds()
form.Wnen.value = Ans
alert(Ans + "\n" + "yyyymmddhhmmss ")

In the microsoft newsgroups, you have consistently been unduly hasty in
responding and have wasted people's time by presenting inefficient code.
There is no need for you to do the same here. You should devote more of
your time to learning from the responses to the amateurish articles that
you post; it will be better for your reputation when you grow up.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 30 '05 #4
ASM
Zvonko wrote:
Hi!

I would like to get the clients date and time (his system time) and
store it somewhere so I can use it in my code later. (insert it to
database!).
Any ideas


and if its clowk gives wrong time ?
why not simplier get server's time ?

urerTime = new Date();
userDay = userTime.getdat e();
userMonth = userTime.getMon th()+1*1;
userYear = userTime.getFul lYear();
userHour = userTime.getHou rs();
userMinutes = userTime.getMin utes();
userSeconds = userTime.getSec onds();
if(userMonth<10 ) userMonth = '0'+userMonth;
if(userHour<10) userHour = '0'+userHour;
if(userMinutes< 10) userMinutes = '0'+userMinutes ;
if(userSeconds< 10) userSeconds = '0'+userSeconds ;

userTime_us = userYear+'/'+userMonth+'/'+userDay+' - '+
userHour+':'+us erMinutes+':'+u serSeconds;

userTime_fr = userDay+'/'+userMonth+'/'+userYear+' - '+
userHour+':'+us erMinutes+':'+u serSeconds;
--
Stephane Moriaux et son [moins] vieux Mac
Aug 31 '05 #5
"Dr John Stockton" <jr*@merlyn.dem on.co.uk> wrote in message
news:CX******** ******@merlyn.d emon.co.uk...

[snip]
You have been told ...
[snip]

John, I prefaced my solution with: "One possible approach ...".

Instead of addressing me why don't you just address the OP?

All you had to say is "Here's a preferred approach.".
In the microsoft newsgroups, you have consistently been unduly hasty in
responding and have wasted people's time by presenting inefficient code.
[snip]

I'm faulted for offering "a" solution when it is requested!

I guess the world should wait for you to answer all of their questions...
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk


Perhaps you should spend a little more time working on your social skills
....
Aug 31 '05 #6

"Zvonko" <zv****@velepro met.hr> wrote in message
news:df******** **@ss405.t-com.hr...
Hi!

I would like to get the clients date and time (his system time) and store
it somewhere so I can use it in my code later. (insert it to database!).
Any ideas


As somebody else noted you want to grab the timezone information as well.
It's very easy to forget this (I happen to be knee deep in timezone code at
the moment) but without it your "client time" doesn't really mean anything.

For getting the code to your database you don't actually have to post a form
(although if you're already posting a form then this is a natural addition
to that). Any of the many techniques now falling under the "AJAX" umbrella
would work to get the data. One simple "old school" technique that works
pretty well across the board is adding the value as a query-string on an img
(or other resource) on the page.

The image tag would point to a server-side script that would evaluate the
query string, store (or do whatever with) the information and return the
image. Assuming that you're using ColdFusion as a server-side script (and
darn it why aren't you?) your img might look like this (abbreviated code -
the getTimeStamp() function would be a custom function that formatted your
information as you like):

<script>
document.write( "<img src='GetClientT ime.cfm?Time=" +
escape(getTimeS tamp()) + "'>");
</script>

You could use a noscript tag to ensure that the img still displays when
script is disabled or use the old (and pretty cheesy) "single pixel GIF" gif
trick. If you want to get a little more complex (but really more "correct")
you could use a plain HTML img tag and change the source of it via script to
send the timestamp.

In any case that server-side GetClientTime.c fm would look for the "Time"
variable and do whatever you like with the value (probably store it). It
would then send the requested image down to the client. (In ColdFusion this
would be via the CFCONTENT tag but pretty much every server-side language
has some option to do this.)

I've a (warning!) very old article on doing this here:

<http://www.depressedpr ess.com/depressedpress/Content/Development/JavaScript/Articles/GIFAsPipe/Index.cfm>

The article actually covers techniques for doing bi-directional
communication (the returned image may contain a cookie) so the provided code
is somewhat more complex than you'd need.

Lastly you'll probably want to consider using an unambiguous datetime
format. The default Date.toString() method may work but this differs from
browser to browser.

Here is a rather verbose function to get a full iso8601 timestamp (local
time with timezone offset) from JavaScript :

function getTimeStamp() {

// Init DatePart vars
var Year,Month,Day, Hours,Minutes,S econds,Millisec onds,TimeZoneIn fo

// Get DateParts
Year = ("000" + CurDate.getFull Year()).slice(-4);
Month = ("0" + (CurDate.getMon th() + 1)).slice(-2);
Day = ("0" + CurDate.getDate ()).slice(-2);
Hours = ("0" + CurDate.getHour s()).slice(-2);
Minutes = ("0" + CurDate.getMinu tes()).slice(-2);
Seconds = ("0" + CurDate.getSeco nds()).slice(-2);
Milliseconds = ("00" + CurDate.getMill iseconds()).sli ce(-3);
// Get TimeZone Information
var TimeZoneOffset = CurDate.getTime zoneOffset();
TimeZoneInfo = (TimeZoneOffset >= 0 ? "-" : "+") + ("0" +
(Math.floor(Mat h.abs(TimeZoneO ffset) / 60))).slice(-2) + ":" + ("00" +
(Math.abs(TimeZ oneOffset) % 60)).slice(-2);

// Return the TimeStamp
return Year + "-" + Month + "-" + Day + "T" + Hours + ":" + Minutes +
":" + Seconds + "." + Milliseconds + TimeZoneInfo;

};

Sorry for being so long-winded... this just happened to coincide with some
work I'm doing. ;^)

Good luck!

Jim Davis
Aug 31 '05 #7
McKirahan said the following on 8/30/2005 9:10 PM:
"Dr John Stockton" <jr*@merlyn.dem on.co.uk> wrote in message
news:CX******** ******@merlyn.d emon.co.uk...

[snip]

You have been told ...

[snip]

John, I prefaced my solution with: "One possible approach ...".

Instead of addressing me why don't you just address the OP?

All you had to say is "Here's a preferred approach.".


But, had he done that, it would not have fed his ego, made him feel
important and would not have allowed him to be pedantic enough. He is a
hypocritical idiot about some things.
In the microsoft newsgroups, you have consistently been unduly hasty in
responding and have wasted people's time by presenting inefficient code.

[snip]

I'm faulted for offering "a" solution when it is requested!

I guess the world should wait for you to answer all of their questions...


He doesn't have the answers, that is why he is so anally pedantic at times.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk

Perhaps you should spend a little more time working on your social skills


He would have to gain some social skills before he could work on them.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Aug 31 '05 #8
JRS: In article <P-ednZ2dnZ2HgXGnn Z2dnSCeiN6dnZ2d RVn-
yJ*****@comcast .com>, dated Tue, 30 Aug 2005 20:10:45, seen in
news:comp.lang. javascript, McKirahan <Ne**@McKirahan .com> posted :
"Dr John Stockton" <jr*@merlyn.dem on.co.uk> wrote in message
news:CX******* *******@merlyn. demon.co.uk...

[snip]
You have been told ...
[snip]

John, I prefaced my solution with: "One possible approach ...".

Instead of addressing me why don't you just address the OP?


Because it was you who rushed in with a very low-grade piece of code, as
has been your habit elsewhere.

All you had to say is "Here's a preferred approach.".
In the microsoft newsgroups, you have consistently been unduly hasty in
responding and have wasted people's time by presenting inefficient code.
[snip]

I'm faulted for offering "a" solution when it is requested!


No, for presenting one which is bad, and which you should have realised
was likely to be so from your previous experience.
Perhaps you should spend a little more time working on your social skills
...


Well, you seem to think that I wish to beat you around the head with a
mallet; you are mistaken, as I would prefer to use a maul or beetle.
But it's near enough what I intended. Soft words are liable to be
misunderstood by those of low ability.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Aug 31 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6538
by: m3ckon | last post by:
HI there, I currently store the date using the getdate() function but how can I store just the time or seperate the time off from a datetime datatype? M3ckon *** Sent via Devdex http://www.devdex.com ***
2
1817
by: Robert | last post by:
I have no problem storing dates + times in a System.DateTime object. In addition, it's easy to output a Time as a string from an existing Date/Time. But I'm having trouble storing a time only. Is there any way to store only a time without the date portion (like 3:00 am) in this data structure? Or, if not, is there another data structure that would be preferable? Thanks
4
6422
by: brfin999 | last post by:
Server time zone 1 hour different from Client time zone. .Net 1.1 c# Win Forms app: actual date 9/25/04 displays 9/24/04 11:00 PM. When I change client time zone to equal server time zone, date displays correctly. Client in Pacific time zone, server in Mountain time zone.
11
2367
by: James Hallam | last post by:
I have read through all the past topics and couldn't find what I was after so... I am looking to store some calculated values (don't flame just yet, just read on!). I have an piece of code behind a form which calculates a percentage completion and an expected completion date of a job. I would like to store this information in a separate table, along with the actual date the values were calculated. Whenever a job is completed I can...
3
5324
by: john | last post by:
I am using MS Sql Express as the backend database for a Microsoft Access front end application. I am using a calendar control to store the desired date in the sql datetime field. The time portion of the field defaults to 12:00am. What I want is to also store the time in the same datetime field as the date, but I want to use a separate control from the calendar control. I.e. I want the user to choose the date from the calendar control,...
7
3258
by: fauxanadu | last post by:
Is it possible to store dates before 01/01/0100 A.D. (such as for as database storing world events would require) using MS Access? Verbose Explination I need to be able to store dates before 100CE in a date field. This is for a world history database that I am building. I am currently storing dates in a database as unformatted text (14 characters: mm/dd/yyyy/. This requires using alot of extra VBA code to validate the dates to ensure...
1
1964
by: suresh_nsnguys | last post by:
Hi, I am new to this Web dowmain.I am little bit confused with this functionality.I am looking forward some sugggesstion from you. Issue: Users allowed to create Ads in my application for displaying in Digital Signage Screen by Settting Start Date/Start Time and End Date/End Time. Based on Start/End date and time ,the particular Ad will get Display in Digital Signage Screen from client machine. While Displaying ads in...
11
10158
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have seen erratic results. I am aware of one known defect where user classes do not show up in the list of types on the Property/Settings page in the visual designer and I am wondering if I am encountering some other peculiar issue, or if there are...
4
1856
by: John A Grandy | last post by:
What are some best practices for storing pure dates and pure times in .NET ? I notice that DateTime.TimeOfDay() returns type TimeSpan , which is certainly sufficient for storing pure times , but not constrained ... Do people write their own classes ? Or have I overlooked one or more intrinsic .NET classes ?
0
10908
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10587
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10649
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7829
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7018
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.