does anyone know computer programming to answer my question?
I'va made this java script program that should tell what time it is but it does nothing. can anyone help me because I need to fix the problrm in 3 hours. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN" "http://http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>sam's assignment</title> <script language="javascript" type="text/javascript"> var localtime = new date(); </script> </head> <Body> <h4> UTC time is <script language="javascript" type =="text/javascript"> document.write(localtime.toUTCstring()); </script> </h4> <h4> local time is <script language="javascript" type =="text/javascript"> document.write(localtime.tolocalstring()); </script> </body> </html>
Public Comments
- Try using the Write(Date()) command. It displays the time/date.
- You are using a deprecated method. The following code gets the user's local time: import java.lang.*; import java.util.*; public class date { public static void main(String[] args) { Date date = new Date(); String time = date.toString(); System.out.println("Date: " + time); time = time.substring(11, time.length() - 8); System.out.println("Time: " + time); } } I'm not sure how to implement this into your html, but I hope this helps.
- 1. replace the 'type =="text/javascript"' with 'type="text/javascript"' (remove the extranous equal sign). 2. Make sure you use correct casing (use Date() instead of date()) - Javascript is case-sensitive
- This snippet works for me. <script type="text/javascript"> var localtime = new Date(); document.write (localtime.toUTCString()) document.write("<br>"); document.write(localtime. toLocaleString()) </script> I messed around with your code, and it seems that capitalization was to blame. Capitalize 'Date' in "var localtime = new Date();", and make sure methods 'toLocaleString' and 'toUTCString' are properly camel-cased.
Powered by Yahoo! Answers