How to Convert a Date to a String in JavaScript

JavaScript, like Java, assigns each piece of data a class. Dates are stored in a compressed format to save memory. Data classes can be converted to make it more convenient to handle the information. Converting a date variable to a string will allow the programmer to work with a section of the data with methods like substr().

Instructions

    • 1

      Instantiate a variable of type Date. The code to do this looks like the following:

      var today = new Date();

    • 2

      Print the date to the screen with a document. Write the command like this:

      document.write(today + "<br />");

    • 3

      Convert the date to a string and write it to the screen with this command:

      document.write(today.toString());

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured