Date Example – Data Type – JavaScript Syntax – JS Date Example

Get 5 Hours of FREE PREMIUM Videos:

LearnVisualStudio.NET Free Preview


LearnVisualStudio.NET Free Preview: Declaring Variables and Assigning Values

I am a lifetime member of LearnVisualStudio.net and a Premium Plus member of dotNetVideos.net.

LearnVisualStudio.net is awesome because it grows in value each year as more videos are added.

dotNetVideos.net is also great because it focuses a lot on MS Certifications and practical interview questions.


- Wade Harvey (IdealProgrammer.com)

LearnVisualStudio Premium Videos

Visual C# 2010 for Absolute Beginners C# for Absolute Beginners C# for Absolute Beginners Study Guide Visual Basic for Absolute Beginners Visual Basic Express Edition Study Guide
Visual Basic 9.0 Language Enhancements Entity Framework Linq To Sql Windows Phone 7 Development Unit Testing
ASP.NET MVC 3 (In Progress) ASP.NET MVC Hands On Project ASP.NET For Absolute Beginners Visual Web Developer C# Study Guide Visual Web Developer VB.NET Study Guide
ASP.NET Controls Series ASP.NET AJAX ASP.NET Architecture Series ASP.NET Server Controls Silverlight 4.0
Windows Presentation Foundation Windows Forms Controls Visual Studio 2010 New Features Visual Studio Team System 2008 Visual Studio Team System Features
Getting Started With Sql Server Express Edition


dotNetVideos Premium Video Catalog

Interview Questions & Answers Windows AzureASP.NET MVC 4Windows Phone 7 (3 Videos)Visual Studio 2011 Application Lifecycle Management
LightSwitchHTML 5SOLIDVisual Studio Add-OnsVisual Studio 2010 ALM Lab Management
ASP.NET 4 Deep Dive Microsoft Enterprise Library 5 with ASP.NET 4 (10 Videos)Virtualization Techniques for Developer (5 Videos)Test Series - 70-519: Designing and Developing Web Applications Using Microsoft .NET Framework 4 (20+ Videos)
Test Series - 70-519: Supplemental70-513: Test Series (MCTS) Windows Communication Foundation 4 (20+ Videos)70-515:Web Applications Development with Microsoft .NET Framework 4 (20+ Videos)Test Series - 70-516: Accessing Data with Microsoft .NET Framework 4 (20+ Videos)Test Series: 70-432: Microsoft SQL Server 2008, Implementation and Maintenance (20+ Videos)
Test Series: 70-433: SQL Server AdministrationFrom Novice To Professional - C# (25 Videos)From Novice To Professional - VB.NET (25 Videos)




Premium (Not Free) Video Tutorials

Free Video Tutorials & Free Tools

Date Example – Data Type – JavaScript Syntax – JS Date Example

Purpose: – Illustrates the for the example.
Prerequistes:

Syntax: var myCurrentDate = new Date(); – Demonstrates creating a Date object and various ways to instantiate, manipulate, and retrieve.

Restrictions: None

Notes:

  • You can build your own library of syntax examples by using same web site over and over and just add new files to it.

Instructions:

  1. Use Visual Web Developer 2008
  2. Create new web site;
    • Click File/New Web Site
    • Select ASP.NET Website Template
    • Select C-Sharp for Language
    • name of Web Site could be JavaScript_Syntax.
  3. Add New folder named "DataType"
    • Right-click project name in solution explorer;
    • add new folder;
    • name of folder could be: DataType
  4. Add HTML Page Named Date to DataType folder
    • Right-click DataType folder;
    • add new item;
    • Select HTML Page
    • HTML Page name could be Date
  5. Click on copy code in code below to copy code into HTML Page Date.htm
  6. Right-click on HTML page Date and select view in browser
  7. View Example In Browser

     HTML |  copy code |? 
    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html>
      <head>
        <title>Boolean</title>
        <script type="text/javascript" >
            //*****************************************************
            // Four ways instantiate a Date object
            //*****************************************************
     
            //  Note: Most of the parameters are optional and if you
            // omit them, a 0 is returned in its place. Months start 
            // with Jan = 0; Feb = 1; etc       
            //*****************************************************
     
            //1. new Date() // current date and time
            var myCurrentDate = new Date();  // current date and time
            document.write("myCurrentDate = " + myCurrentDate);
            document.write("<br />");
     
            //2. new Date(milliseconds) //milliseconds since 1970/01/01
            var myMillisecondsDate = new Date(50000000);  //milliseconds since 1970/01/01
            document.write("myMillisecondsDate = " + myMillisecondsDate);
            document.write("<br />");
     
            //3. new Date(dateString)
            var myDateString = new Date("Jan 1, 2010");
            document.write("myDateString = " + myDateString);
            document.write("<br />");
     
            //4. new Date(year, month, day, hours, minutes, seconds, milliseconds)
            var myDateParts = new Date(2010, 1, 15, 13, 59, 48, 37);
            document.write("myDateParts = " + myDateParts);
            document.write("<br />");
     
            //*****************************************************
            // SetDate method allows you to set a date or add or subtract to a date
            //*****************************************************
     
     
     
            var mySetDate = new Date();
            mySetDate.setFullYear(2010, 0, 14);
            document.write("mySetDate = " + mySetDate);
            document.write("<br />");
     
            var myGetDate10 = new Date();
            myGetDate10.setDate(myGetDate10.getDate() + 10);
            document.write("myGetDate10 = " + myGetDate10);
            document.write("<br />");
     
            //*****************************************************
            // How to format the date to locale area
            //*****************************************************
     
            var myDate = new Date();
            document.write(myDate.toLocaleDateString());
            document.write("<br />");
     
            //*****************************************************
            // Date Object Methods
            //*****************************************************
     
     
    //Method 	    Description
    //getDate() 	Returns the day of the month (from 1-31)
    //getDay() 	    Returns the day of the week (from 0-6)
    //getFullYear() Returns the year (four digits)
    //getHours() 	Returns the hour (from 0-23)
    //getMilliseconds() Returns the milliseconds (from 0-999)
    //getMinutes() 	Returns the minutes (from 0-59)
    //getMonth() 	Returns the month (from 0-11)
    //getSeconds() 	Returns the seconds (from 0-59)
    //getTime() 	Returns the number of milliseconds since midnight Jan 1, 1970
    //getTimezoneOffset() 	Returns the time difference between GMT and local time, in minutes
    //getUTCDate() 	Returns the day of the month, according to universal time (from 1-31)
    //getUTCDay() 	Returns the day of the week, according to universal time (from 0-6)
    //getUTCFullYear() 	Returns the year, according to universal time (four digits)
    //getUTCHours() 	Returns the hour, according to universal time (from 0-23)
    //getUTCMilliseconds() 	Returns the milliseconds, according to universal time (from 0-999)
    //getUTCMinutes() 	Returns the minutes, according to universal time (from 0-59)
    //getUTCMonth() 	Returns the month, according to universal time (from 0-11)
    //getUTCSeconds() 	Returns the seconds, according to universal time (from 0-59)
    //getYear() 	Deprecated. Use the getFullYear() method instead
    //parse() 	Parses a date string and returns the number of milliseconds since midnight of January 1, 1970
    //setDate() 	Sets the day of the month (from 1-31)
    //setFullYear() 	Sets the year (four digits)
    //setHours() 	Sets the hour (from 0-23)
    //setMilliseconds() 	Sets the milliseconds (from 0-999)
    //setMinutes() 	Set the minutes (from 0-59)
    //setMonth() 	Sets the month (from 0-11)
    //setSeconds() 	Sets the seconds (from 0-59)
    //setTime() 	Sets a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970
    //setUTCDate() 	Sets the day of the month, according to universal time (from 1-31)
    //setUTCFullYear() 	Sets the year, according to universal time (four digits)
    //setUTCHours() 	Sets the hour, according to universal time (from 0-23)
    //setUTCMilliseconds() 	Sets the milliseconds, according to universal time (from 0-999)
    //setUTCMinutes() 	Set the minutes, according to universal time (from 0-59)
    //setUTCMonth() 	Sets the month, according to universal time (from 0-11)
    //setUTCSeconds() 	Set the seconds, according to universal time (from 0-59)
    //setYear() 	Deprecated. Use the setFullYear() method instead
    //toDateString() 	Converts the date portion of a Date object into a readable string
    //toGMTString() 	Deprecated. Use the toUTCString() method instead
    //toLocaleDateString() 	Returns the date portion of a Date object as a string, using locale conventions
    //toLocaleTimeString() 	Returns the time portion of a Date object as a string, using locale conventions
    //toLocaleString() 	Converts a Date object to a string, using locale conventions
    //toString() 	Converts a Date object to a string
    //toTimeString() 	Converts the time portion of a Date object to a string
    //toUTCString() 	Converts a Date object to a string, according to universal time
    //UTC() 	Returns the number of milliseconds in a date string since midnight of January 1, 1970, according to universal time
    //valueOf() 	Returns the primitive value of a Date object
     
     
     
            //*****************************************************
            // How to Compare a date
            //*****************************************************
     
            var myDate = new Date();
            myDate.setFullYear(2010, 06, 14);
            var today = new Date();
     
            if (myDate > today) {
                alert("Today is before 14th July 2010");
            }
            else {
                alert("Today is after 14th July 2010");
            }
     
     
        </script>
      </head>
      <body>
      </body>
    </html>
     
     
     

Related posts:

  1. Array Example – Data Type – JavaScript Syntax – JS Array Example Array Example - Data Type - JavaScript Syntax - JS...
  2. Boolean Example – Data Type – JavaScript Syntax – JS Boolean Example Boolean Example - Data Type - JavaScript Syntax - JS...
  3. 3D Example – Ajax Layer – JavaScript Syntax – JS 3D Example 3D Example - Ajax Layer - JavaScript Syntax - JS...
  4. VB.NET String Format DateTime Source Code Example VB.NET String Format DateTime Source Code Example...
  5. C# String.Format DateTime Source Code Example C# String.Format DateTime Source Code Example...

Related posts brought to you by Yet Another Related Posts Plugin.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Powered by WP Hashcash

This blog uses the cross-linker plugin developed by Web-Developers.Net