Friday, 3 May 2013

JavaScript Basics

 JavaScript Array:

  Here i am going to Guide you on JavaScript Arrays. Array in JS is Same as in PHP and other Programming Languages.    Here is the Syntax for creating Array,

Syntax:

var fruitArray = new Array( "apple", "orange", "mango","banana" );
OR
var fruitArray = new Array[ "apple", "orange", "mango","banana" ];

 In this Array,

  fruitsarray[1] is the First element,

 fruitsarray[2] is the Second element,

 fruitsarray[3] is the Third element,

 fruitsarray[4] is the Fourth element.

Dates:           

new Date( ):

        This will display Current Date with Time. But We Programmers won't like to display Dates with time. But we will format it with some functions and display it.       
Here is a program to Display current date As many clients wants to display in Web Pages.

Function to display Current Date:  

function displayTodaysDate()
{
var x = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday");
var z = new Array("January","February","March","April", "May","June",
"July", "August", "September","October","November","December");

var d = new Date();
var day = d.getDay();
var month = d.getMonth();

// Assemble the string to display
var s = x[day] + ", " + d.getDate() + " " + (z[month]) + " " + (d.getFullYear());

document.write(s);
}

Output:  Friday, 3 May 2013

 Just Copy it in your Page and then Call this function using the below code,

<script type="text/javascript">

displayTodaysDate();

</script>

Other Syntax:

                Please Use any of the below syntax below to get desired date output in javascript
new Date(milliseconds)
new Date(datestring) new Date(year,month,date[,hour,minute,second,millisecond ])

2 comments:

  1. Nice blog...Very useful information is providing by ur blog. Great beginning php tutorials Very clear and helpful for beginners.

    ReplyDelete


  2. Thank you for this blog post it actually couldn't have come at a better time for me !!

    Hire Yii Framework Developers

    ReplyDelete