JavaScript: toUTCString() method



Author: Ronald S. Holland
at
Total Application Works





To contact us



[HOME] [Consulting] [Design] [Maintenance] [Project] [Testing] [Training] [Turnkey] [Java] [C++] [SQL] [HTML] [JavaScript ]

© 2002 - 2010 All Rights Reserved Total Application Works


  • Tell a friend about this site (copy and paste the following HTML page into a file (e.g., using Notepad).)
  • <html>
    <head>
    <title>Example of a link </title>
    </head>
    <body>
    <a href="http://sumtotalz.com/TotalAppsWorks/Javascript/Date/JS_toUTCString.html">
    Lists and their Tags </a>
    </table>
    </body>
    </html>

JavaScript Date Object

Introduction

The purpose of this tutorial is to introduce and briefly explore JavaScript functions and the toUTCString() method. This tutorial assumes that you have read and mastered my tutorials on:

  1. Table Tags
  2. Form Tags
  3. Introduction to JavaScript
  4. JS: basic Calculator
This tutorial assumes that you have some prior programming experience. It is not intended to be a comprehensive discussion on JavaScript or programming. In this tutorial, we will briefly discuss functions, as we ease into JavaScript, and build on what we learned in JS: basic Calculator (see ref. 3 above). In the next section, we will briefly describe JavaScript basics.

What is JavaScript?

JavaScript is a scripting language developed by Netscape that enables Web designers to create interactive sites/web pages. JavaScript and Java have many features and structures in common, however, they were developed independently. When JavaScript embedded within HTML source code, it enables Web designers to spice up their sites with dynamic content. JavaScript is used in Web pages designers to:

  • Improve the Web page dynamic content design;
  • Add interactivity to HTML pages;
  • Validate forms and gather data from users;
  • Detect browsers;
  • Create cookies;
  • Etc.
JavaScript is a scripting/interpreted language, which can execute without having to compile the source code. Java and JavaScript are similar but are not the same. They are two completely different languages in both concept and design. It runs on the client's computer and does not require constant downloads from your web site.

What is a JavaScript toUTCString() method?

The JavaScript Date object is responsible for JavaScript's date and time handling. The following table contains the Date object methods and a brief description of its functionality/behavior.

Date Object Methods
Method Description
toUTCString() Converts a Date object, according to universal time, to a string.
Figure 1: toUTCString() method

How do you use the JavaScript toUTCString() method?

Figure 2 shows you how to use the Date object to toUTCString(). A variable named myDate is created and the date values are stored in it.

Date Object Methods
Example of Using toUTCString() code Demo of toUTCString() code
<html>
<head>

<script type="text/javascript">
function to_UTCString() {
   var myDate = new Date();
   myDate.toUTCString();
   alert( "Value of myDate after to_UTCString() " + 
         myDate.toUTCString()  ) ;
   document.getElementById('toUTCStringtxt').innerHTML=
       "Value of myDate after to_UTCString()  " + 
          myDate.toUTCString()
}

</script>
</head>
<body>
<button onclick="to_UTCString()"> value of myDate  

<div id="toUTCStringtxt"> </div>

</body>
</html>






Figure 2: toUTCString() method


After pressing the value of date object after call to toUTCString() method, the following is displayed.









[HOME] [Consulting] [Design] [Maintenance] [Project] [Testing] [Training] [Turnkey] [Java] [C++] [SQL] [HTML] [JavaScript ]



To contact us

© 2002 - 2010 All Rights Reserved Total Application Works