LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2003, 11:55 AM   #1
meluser
Member
 
Registered: Mar 2003
Posts: 65

Rep: Reputation: 15
html form current datetime


hi,

i have a form that has a field, that i would like to set the field to the current date and time in the context of
0000-00-00 00:00:00

could someone help.

Cheers,
Mel
 
Old 04-15-2003, 01:38 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
If you want to use javascript then use quick one I just wrote:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Current Date and Time</TITLE>
</HEAD>
<BODY>
<FORM name="form1"><INPUT name="box1" type="text"></FORM>

<SCRIPT type="text/javascript" language="JavaScript">

function update(){
time = new Date();
year = (time.getYear() + 1900);
month = (time.getMonth() + 1);
date = time.getDate();
hours = time.getHours();
mins = time.getMinutes();
secs = time.getSeconds();
if(mins.length<2){mins = "0"+secs}
if(secs.length<2){secs = "0"+secs}
if(month.length<2){month = "0"+secs}
if(date.length<2){date  = "0"+secs}


// Config Starts
format = year+"-"+month+"-"+date+" "+hours+":"+mins+":"+secs;
document.form1.box1.value = format;
// Config Ends
}
setInterval("update()",1000);
</SCRIPT>
</BODY>
</HTML>

If you have SSI you can use that too.
 
Old 04-15-2003, 03:26 PM   #3
meluser
Member
 
Registered: Mar 2003
Posts: 65

Original Poster
Rep: Reputation: 15
thanks for the script.

what i am trying to do, is to display the current date and time only. not live date and time, so the user will be able to adjust it. with the nice script you sent me we cant adjust it!!!

Cheers,
 
Old 04-16-2003, 12:25 PM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
Use this then:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Current Date and Time</TITLE>
</HEAD>
<BODY>
<FORM name="form1"><INPUT name="box1" type="text"></FORM>

<SCRIPT type="text/javascript" language="JavaScript">

time = new Date();
year = (time.getYear() + 1900);
month = (time.getMonth() + 1);
date = time.getDate();
hours = time.getHours();
mins = time.getMinutes();
secs = time.getSeconds();
if(mins.length<2){mins = "0"+secs}
if(secs.length<2){secs = "0"+secs}
if(month.length<2){month = "0"+secs}
if(date.length<2){date  = "0"+secs}


// Config Starts
format = year+"-"+month+"-"+date+" "+hours+":"+mins+":"+secs;
document.form1.box1.value = format;
// Config Ends

</SCRIPT>
</BODY>
</HTML>
If you wand static text and have SSI I would reccomend using that as it will be compatible with any browser.
 
Old 04-16-2003, 01:53 PM   #5
meluser
Member
 
Registered: Mar 2003
Posts: 65

Original Poster
Rep: Reputation: 15
thanks very much.

the display i get is showing the year wrong!!

3903-4-16 19:48:34


another question. i would like to have another field within the frame, but with the current time 10 minutes ago!!!. so with the above it would display

2003-4-16 19:38:34

thanks one again
 
Old 04-16-2003, 02:02 PM   #6
meluser
Member
 
Registered: Mar 2003
Posts: 65

Original Poster
Rep: Reputation: 15
another question. could i possibly display the results in the format 0000-00-00 00:00:00

cheers
 
Old 04-16-2003, 02:46 PM   #7
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I actually made some typos - this should work:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Current Date and Time</TITLE>
</HEAD>
<BODY>
<FORM name="form1"><INPUT name="box1" type="text"><INPUT name="box2" type="text"></FORM>

<SCRIPT type="text/javascript" language="JavaScript">

time = new Date();
year = new String((time.getYear() + 1900));
month = new String((time.getMonth() + 1));
date = new String(time.getDate());
hours = new String(time.getHours());
mins = new String(time.getMinutes());
secs = new String(time.getSeconds());
if(mins.length<2){mins = "0"+mins}
if(secs.length<2){secs = "0"+secs}
if(month.length<2){month = "0"+month}
if(date.length<2){date  = "0"+date}


// Config Starts
box1format = year+"-"+month+"-"+date+" "+hours+":"+mins+":"+secs;
box2format = year+"-"+month+"-"+date+" "+hours+":"+(mins-10)+":"+secs;
document.form1.box1.value = box1format;
document.form1.box2.value = box2format;
// Config Ends

</SCRIPT>
</BODY>
</HTML>
 
Old 04-16-2003, 02:53 PM   #8
meluser
Member
 
Registered: Mar 2003
Posts: 65

Original Poster
Rep: Reputation: 15
excellent results, thanks.

the year is still not right
3903-04-16 20:52:35
3903-04-16 20:42:35
 
Old 04-16-2003, 02:56 PM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
It is fine for me - what browser are you using - I have had this problem before.
 
Old 04-16-2003, 02:57 PM   #10
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I jusst tried it in IE and I see what you mean.
 
Old 04-16-2003, 02:59 PM   #11
meluser
Member
 
Registered: Mar 2003
Posts: 65

Original Poster
Rep: Reputation: 15
Hi,

i have a way to solve it till 2004. by removing the get year. but i dont think this is good!!


thanks for the help. i have another question. is it possible to implement this in a pop up calendar!!!! date, and time

Chers,
 
Old 04-16-2003, 03:04 PM   #12
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
This seems OK:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Current Date and Time</TITLE>
</HEAD>
<BODY>
<FORM name="form1"><INPUT name="box1" type="text"><INPUT name="box2" type="text"></FORM>

<SCRIPT type="text/javascript" language="JavaScript">

time = new Date();
year = new String(time.getYear());
if(navigator.appName != "Microsoft Internet Explorer"){year = (year*1)+1900}
month = new String((time.getMonth() + 1));
date = new String(time.getDate());
hours = new String(time.getHours());
mins = new String(time.getMinutes());
secs = new String(time.getSeconds());
if(mins.length<2){mins = "0"+mins}
if(secs.length<2){secs = "0"+secs}
if(month.length<2){month = "0"+month}
if(date.length<2){date  = "0"+date}


// Config Starts
box1format = year+"-"+month+"-"+date+" "+hours+":"+mins+":"+secs;
box2format = year+"-"+month+"-"+date+" "+hours+":"+(mins-10)+":"+secs;
document.form1.box1.value = box1format;
document.form1.box2.value = box2format;
// Config Ends

</SCRIPT>
</BODY>
</HTML>
 
Old 04-16-2003, 03:06 PM   #13
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 79
I'm not sure what you mean by in a popup calendar - the chances are yes, but I ain't gonna write it!
 
Old 04-16-2003, 03:11 PM   #14
meluser
Member
 
Registered: Mar 2003
Posts: 65

Original Poster
Rep: Reputation: 15
another problem

3903-04-16 21:09:44
3903-04-16 21:-1:44
 
Old 04-16-2003, 03:16 PM   #15
meluser
Member
 
Registered: Mar 2003
Posts: 65

Original Poster
Rep: Reputation: 15
thanks i got 2003 working.

this is some results.
2003-04-16 21:5:01
2003-04-16 21:15:01

is there anyway to display 21:5:01 as 21:05:01

cheers
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
To call a new form from Current form in QT Desginer kiranbud Linux - Software 0 11-25-2005 11:56 PM
Html Form File Cottsay General 0 11-05-2005 01:30 PM
html question: form henrikanttonen Programming 4 08-13-2004 07:28 AM
Contact form on HTML Gerardoj Linux - General 1 03-26-2004 02:08 AM
problem with html form meluser Linux - Software 4 03-15-2003 12:28 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration