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
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
04-15-2003, 11:55 AM
#1
Member
Registered: Mar 2003
Posts: 65
Rep:
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
04-15-2003, 01:38 PM
#2
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
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.
04-15-2003, 03:26 PM
#3
Member
Registered: Mar 2003
Posts: 65
Original Poster
Rep:
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,
04-16-2003, 12:25 PM
#4
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
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.
04-16-2003, 01:53 PM
#5
Member
Registered: Mar 2003
Posts: 65
Original Poster
Rep:
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
04-16-2003, 02:02 PM
#6
Member
Registered: Mar 2003
Posts: 65
Original Poster
Rep:
another question. could i possibly display the results in the format 0000-00-00 00:00:00
cheers
04-16-2003, 02:46 PM
#7
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
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>
04-16-2003, 02:53 PM
#8
Member
Registered: Mar 2003
Posts: 65
Original Poster
Rep:
excellent results, thanks.
the year is still not right
3903-04-16 20:52:35
3903-04-16 20:42:35
04-16-2003, 02:56 PM
#9
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
It is fine for me - what browser are you using - I have had this problem before.
04-16-2003, 02:57 PM
#10
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
I jusst tried it in IE and I see what you mean.
04-16-2003, 02:59 PM
#11
Member
Registered: Mar 2003
Posts: 65
Original Poster
Rep:
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,
04-16-2003, 03:04 PM
#12
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
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>
04-16-2003, 03:06 PM
#13
Moderator
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047
Rep:
I'm not sure what you mean by in a popup calendar - the chances are yes, but I ain't gonna write it!
04-16-2003, 03:11 PM
#14
Member
Registered: Mar 2003
Posts: 65
Original Poster
Rep:
another problem
3903-04-16 21:09:44
3903-04-16 21:-1:44
04-16-2003, 03:16 PM
#15
Member
Registered: Mar 2003
Posts: 65
Original Poster
Rep:
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
All times are GMT -5. The time now is 09:40 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News