SlideShare a Scribd company logo
IIS
(DEEMED TO BE UNIVERSITY)
Web Application Development (CBCA 304)
Topic : Date and time
Submitted By:
Garima
Agarwal
Garima Garg
Kajal Agarwal
Vinita kapoor
CONTENT
 JS Dates
 JS Dates Formats
 JS Date Get Methods
 JS Date Set Methods
Additional Topics
 Meta Tag
 Dialog Tag
JAVASCRIPT DATE OBJECT LETS US WORK
WITH DATES:
Example:
<script>
var d = new Date();
document.getElementByI
d("demo").innerHTML =
d;
</script>
Output:
Wed Mar 07 2019
10:40:02 GMT+0530
(India Standard Time)
Note:
By default, JavaScript will use the browser's time
zone and display a date as a full text string
CREATING DATE OBJECTS
Date objects are created with the new Date()
constructor.
There are 4 ways to create a new date object:
 new Date()
 new Date(year, month, day, hours, minutes,
seconds, milliseconds)
 new Date(milliseconds)
 new Date(date string)
NEW DATE(YEAR, MONTH, ...)
 new Date(year, month, ...) creates a new date
object with a specified date and time.
 7 numbers specify year, month, day, hour,
minute, second, and millisecond (in that order):
Example:
<script>
var d = new Date(2018, 11, 24, 10, 33, 30, 0);
document.getElementById("demo").innerHTML = d;
</script>
Output:
Mon Dec 24 2018 10:33:30 GMT+0530 (India Standard
Time)
CENTURY YEAR
One and two digit years will be interpreted as 19xx:
Example:
<script>
var d = new Date(99, 11, 24);
document.getElementById("demo").innerHTML = d;
</script>
Output:
Fri Dec 24 1999 00:00:00 GMT+0530 (India Standard
Time)
NEW DATE(DATESTRING)
new Date(dateString) creates a new date object from
a date string:
Example:
<script>
var d = new Date("October 13, 2014 11:13:00");
document.getElementById("demo").innerHTML = d;
</script>
Output:
Mon Oct 13 2014 11:13:00 GMT+0530 (India
Standard Time
JAVASCRIPT STORES DATES AS MILLISECONDS
 JavaScript stores dates as number of milliseconds
since January 01, 1970, 00:00:00 UTC (Universal
Time Coordinated).
 Zero time is January 01, 1970 00:00:00 UTC.
NEW DATE(MILLISECONDS)
 new Date(milliseconds) creates a new date object
as zero time plus milliseconds:
Example:
<script>
var d = new Date(0);
document.getElementById("demo").innerHTML = d;
</script>
Output:
Thu Jan 01 1970 05:30:00 GMT+0530 (India
Standard Time)
THE TOUTCSTRING() METHOD CONVERTS A DATE TO A
UTC STRING (A DATE DISPLAY STANDARD).
Example:
<script>
var d = new Date();
document.getElementById("demo").innerHTML =
d.toUTCString();
</script>
Output:
Wed, 06 Mar 2019 18:27:06 GMT
THE TODATESTRING() METHOD
CONVERTS A DATE TO A MORE
READABLE FORMAT:
Example:
<script>
var d = new Date();
document.getElementById("demo").innerHTML =
d.toDateString();
</script>
Output:
Thu Mar 07 2019
JAVASCRIPT DATE INPUT
There are generally 3 types of JavaScript date input
formats
TYPE EXAMPLE
ISO Date "2015-03-25" (The
International Standard)
Short Date 03/25/2015
Long Date March 25 2015 or 25 March
2015
ISO DATES (YEAR AND MONTH)
ISO dates can be written without specifying the day (YYYY-
MM):
Example:
<script>
var d = new Date("2015-03");
document.getElementById("demo").innerHTML = d;
</script>
Output:
Sun Mar 01 2015 05:30:00 GMT+0530 (India Standard
Time)
TIME ZONES
 When setting a date, without specifying the time
zone, JavaScript will use the browser's time zone.
WARNINGS !
 In some browsers, months or days with no leading zeroes may produce
an
error:
Example:
var d = new Date("2015-3-25");
-----------------------------------------------------------------------------------
 The behavior of "YYYY/MM/DD" is undefined.
Some browsers will try to guess the format. Some will return NaN.
Example:
var d = new Date("2015/03/25");
------------------------------------------------------------------------------------
 The behavior of "DD-MM-YYYY" is also undefined.
Some browsers will try to guess the format. Some will return NaN.
Example:
var d = new Date("25-03-2015");
DATE INPUT - PARSING DATES
If you have a valid date string, you can use the Date.parse()
method to
convert it to milliseconds.
Date.parse() returns the number of milliseconds between the
date and
January 1, 1970:
Example:
var msec = Date.parse("March 21, 2012");
document.getElementById("demo").innerHTML = msec;
Output:
1332268200000
JAVASCRIPT GET DATE METHODS
Method Description
getFullYear() Get the year as a four digit number (yyyy)
getMonth() Get the month as a number (0-11)
getDate() Get the day as a number (1-31)
getHours() Get the hour (0-23)
getMinutes() Get the minute (0-59)
getSeconds() Get the second (0-59)
getMilliseconds() Get the second (0-59)
getTime() Get the time (milliseconds since January
1, 1970)
getDay() Get the weekday as a number (0-6)
Date.now() Get the time. ECMAScript 5.
THE GETFULLYEAR() METHOD
The getFullYear() method returns the year of a date as a four
digit number:
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getFullYear();
Output:
2019
THE GETMONTH() METHOD
The getMonth() method returns the month of a date as a number
(0,11):
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getMonth();
Output:
3
THE GETDATE() METHOD
The getDate() method returns the day of a data
as a number(1-31):
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getDate();
Output:
11
THE GETHOURS() METHOD
The getHours() method returns the hours of a
date as a number (0-23):
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getHours();
Output:
23
THE GETMINUTES() METHOD
The getMinutes() method returns the minutes of
a date as a number (0-59):
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getMinutes();
Output:
7
THE GETSECONDS() METHOD
The getSeconds() method returns the seconds of a date as a number
(0-59):
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getSeconds();
Output:
22
THE GETMILLISECONDS() METHOD
The getMilliseconds() method returns the milliseconds of a date as a
number (0-999):
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getMilliseconds();
Output:
661
THE GETDAY() METHOD
The getDay() method returns the weekday of a date as a number (0-6):
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getDay();
Output:
6
Note: In JavaScript, the first day of the week (0) means "Sunday", even if
some countries in the world consider the first day of the week to be
"Monday"
You can use an array of names, and getDay() to return the
weekday as a name:
Example:
var d = new Date();
var days = ["Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"];
document.getElementById("demo").innerHTML =
days[d.getDay()];
Output:
Wednesday
THE GETTIME() METHOD
The getTime() method returns the number of milliseconds since
January 1,
1970:
Example:
var d = new Date();
document.getElementById("demo").innerHTML = d.getTime();
Output:
1551893921931
UTC DATE METHODS
UTC date methods are used for working with UTC dates
(Universal Time Zone
dates):
Method Description
getUTCDate() Same as getDate(), but returns the UTC date
getUTCDay() Same as getDay(), but returns the UTC day
getUTCFullYear() Same as getFullYear(), but returns the UTC Year
getUTCHours() Same as getHours(), but returns the UTC hours
getUTCMillisecond() Same as getMilliseconds(), but returns the UTC
Millisecond
getUTCMinutes() Same as getMinutes(), but returns the UTC Minutes
getUTCMonth() Same as getMonth(), but returns the UTC Month
getUTCSecond() Same as getSecond(), but returns the UTC Seconds
Data and time

More Related Content

What's hot

Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom ManipulationMohammed Arif
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in phpCPD INDIA
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An IntroductionManvendra Singh
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScriptShahDhruv21
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)WebStackAcademy
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesHùng Nguyễn Huy
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...Edureka!
 

What's hot (20)

Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
JavaScript & Dom Manipulation
JavaScript & Dom ManipulationJavaScript & Dom Manipulation
JavaScript & Dom Manipulation
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
JavaScript: Events Handling
JavaScript: Events HandlingJavaScript: Events Handling
JavaScript: Events Handling
 
Oops concepts in php
Oops concepts in phpOops concepts in php
Oops concepts in php
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Android Intent.pptx
Android Intent.pptxAndroid Intent.pptx
Android Intent.pptx
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
jQuery
jQueryjQuery
jQuery
 
Angular
AngularAngular
Angular
 
Delegates and events in C#
Delegates and events in C#Delegates and events in C#
Delegates and events in C#
 
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
 
Android Networking
Android NetworkingAndroid Networking
Android Networking
 

Similar to Data and time

enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docxMichel Valentim
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfjaipur2
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfankit11134
 
11. Objects and Classes
11. Objects and Classes11. Objects and Classes
11. Objects and ClassesIntro C# Book
 
JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8Serhii Kartashov
 
FYBSC IT Web Programming Unit III Core Javascript
FYBSC IT Web Programming Unit III  Core JavascriptFYBSC IT Web Programming Unit III  Core Javascript
FYBSC IT Web Programming Unit III Core JavascriptArti Parab Academics
 
New Java Date/Time API
New Java Date/Time APINew Java Date/Time API
New Java Date/Time APIJuliet Nkwor
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08HUST
 
Programming Google apps with the G Suite APIs
Programming Google apps with the G Suite APIsProgramming Google apps with the G Suite APIs
Programming Google apps with the G Suite APIsDevFest DC
 
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...wesley chun
 
Date object.pptx date and object v
Date object.pptx date and object        vDate object.pptx date and object        v
Date object.pptx date and object v22x026
 
27. mathematical, date and time functions in VB Script
27. mathematical, date and time  functions in VB Script27. mathematical, date and time  functions in VB Script
27. mathematical, date and time functions in VB ScriptVARSHAKUMARI49
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]MomenMostafa
 

Similar to Data and time (20)

enum_comp_exercicio01.docx
enum_comp_exercicio01.docxenum_comp_exercicio01.docx
enum_comp_exercicio01.docx
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
 
17 ruby date time
17 ruby date time17 ruby date time
17 ruby date time
 
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
 
11. Objects and Classes
11. Objects and Classes11. Objects and Classes
11. Objects and Classes
 
Java script
Java scriptJava script
Java script
 
Computer programming 2 Lesson 14
Computer programming 2  Lesson 14Computer programming 2  Lesson 14
Computer programming 2 Lesson 14
 
Jsr310
Jsr310Jsr310
Jsr310
 
JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8
 
FYBSC IT Web Programming Unit III Core Javascript
FYBSC IT Web Programming Unit III  Core JavascriptFYBSC IT Web Programming Unit III  Core Javascript
FYBSC IT Web Programming Unit III Core Javascript
 
Java Day-7
Java Day-7Java Day-7
Java Day-7
 
Python datetime
Python datetimePython datetime
Python datetime
 
New Java Date/Time API
New Java Date/Time APINew Java Date/Time API
New Java Date/Time API
 
Csphtp1 08
Csphtp1 08Csphtp1 08
Csphtp1 08
 
Programming Google apps with the G Suite APIs
Programming Google apps with the G Suite APIsProgramming Google apps with the G Suite APIs
Programming Google apps with the G Suite APIs
 
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
Power your apps with Gmail, Google Drive, Calendar, Sheets, Slides, Apps Scri...
 
Date object.pptx date and object v
Date object.pptx date and object        vDate object.pptx date and object        v
Date object.pptx date and object v
 
27. mathematical, date and time functions in VB Script
27. mathematical, date and time  functions in VB Script27. mathematical, date and time  functions in VB Script
27. mathematical, date and time functions in VB Script
 
C programming & data structure [arrays & pointers]
C programming & data structure   [arrays & pointers]C programming & data structure   [arrays & pointers]
C programming & data structure [arrays & pointers]
 
Domain Driven Design In C#3.0
Domain Driven Design In C#3.0Domain Driven Design In C#3.0
Domain Driven Design In C#3.0
 

Recently uploaded

Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfKamal Acharya
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdfKamal Acharya
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-IVigneshvaranMech
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdfKamal Acharya
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfKamal Acharya
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdfKamal Acharya
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfKamal Acharya
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdfAhmedHussein950959
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageRCC Institute of Information Technology
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfNurvisNavarroSanchez
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdfKamal Acharya
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdfKamal Acharya
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.PrashantGoswami42
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf884710SadaqatAli
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxVishalDeshpande27
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionjeevanprasad8
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdfKamal Acharya
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
 

Recently uploaded (20)

Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Toll tax management system project report..pdf
Toll tax management system project report..pdfToll tax management system project report..pdf
Toll tax management system project report..pdf
 
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES  INTRODUCTION UNIT-IENERGY STORAGE DEVICES  INTRODUCTION UNIT-I
ENERGY STORAGE DEVICES INTRODUCTION UNIT-I
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
A case study of cinema management system project report..pdf
A case study of cinema management system project report..pdfA case study of cinema management system project report..pdf
A case study of cinema management system project report..pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Scaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltageScaling in conventional MOSFET for constant electric field and constant voltage
Scaling in conventional MOSFET for constant electric field and constant voltage
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
shape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptxshape functions of 1D and 2 D rectangular elements.pptx
shape functions of 1D and 2 D rectangular elements.pptx
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 

Data and time

  • 1. IIS (DEEMED TO BE UNIVERSITY) Web Application Development (CBCA 304) Topic : Date and time Submitted By: Garima Agarwal Garima Garg Kajal Agarwal Vinita kapoor
  • 2. CONTENT  JS Dates  JS Dates Formats  JS Date Get Methods  JS Date Set Methods Additional Topics  Meta Tag  Dialog Tag
  • 3. JAVASCRIPT DATE OBJECT LETS US WORK WITH DATES: Example: <script> var d = new Date(); document.getElementByI d("demo").innerHTML = d; </script> Output: Wed Mar 07 2019 10:40:02 GMT+0530 (India Standard Time) Note: By default, JavaScript will use the browser's time zone and display a date as a full text string
  • 4. CREATING DATE OBJECTS Date objects are created with the new Date() constructor. There are 4 ways to create a new date object:  new Date()  new Date(year, month, day, hours, minutes, seconds, milliseconds)  new Date(milliseconds)  new Date(date string)
  • 5. NEW DATE(YEAR, MONTH, ...)  new Date(year, month, ...) creates a new date object with a specified date and time.  7 numbers specify year, month, day, hour, minute, second, and millisecond (in that order): Example: <script> var d = new Date(2018, 11, 24, 10, 33, 30, 0); document.getElementById("demo").innerHTML = d; </script> Output: Mon Dec 24 2018 10:33:30 GMT+0530 (India Standard Time)
  • 6. CENTURY YEAR One and two digit years will be interpreted as 19xx: Example: <script> var d = new Date(99, 11, 24); document.getElementById("demo").innerHTML = d; </script> Output: Fri Dec 24 1999 00:00:00 GMT+0530 (India Standard Time)
  • 7. NEW DATE(DATESTRING) new Date(dateString) creates a new date object from a date string: Example: <script> var d = new Date("October 13, 2014 11:13:00"); document.getElementById("demo").innerHTML = d; </script> Output: Mon Oct 13 2014 11:13:00 GMT+0530 (India Standard Time
  • 8. JAVASCRIPT STORES DATES AS MILLISECONDS  JavaScript stores dates as number of milliseconds since January 01, 1970, 00:00:00 UTC (Universal Time Coordinated).  Zero time is January 01, 1970 00:00:00 UTC.
  • 9. NEW DATE(MILLISECONDS)  new Date(milliseconds) creates a new date object as zero time plus milliseconds: Example: <script> var d = new Date(0); document.getElementById("demo").innerHTML = d; </script> Output: Thu Jan 01 1970 05:30:00 GMT+0530 (India Standard Time)
  • 10. THE TOUTCSTRING() METHOD CONVERTS A DATE TO A UTC STRING (A DATE DISPLAY STANDARD). Example: <script> var d = new Date(); document.getElementById("demo").innerHTML = d.toUTCString(); </script> Output: Wed, 06 Mar 2019 18:27:06 GMT
  • 11. THE TODATESTRING() METHOD CONVERTS A DATE TO A MORE READABLE FORMAT: Example: <script> var d = new Date(); document.getElementById("demo").innerHTML = d.toDateString(); </script> Output: Thu Mar 07 2019
  • 12.
  • 13. JAVASCRIPT DATE INPUT There are generally 3 types of JavaScript date input formats TYPE EXAMPLE ISO Date "2015-03-25" (The International Standard) Short Date 03/25/2015 Long Date March 25 2015 or 25 March 2015
  • 14. ISO DATES (YEAR AND MONTH) ISO dates can be written without specifying the day (YYYY- MM): Example: <script> var d = new Date("2015-03"); document.getElementById("demo").innerHTML = d; </script> Output: Sun Mar 01 2015 05:30:00 GMT+0530 (India Standard Time)
  • 15. TIME ZONES  When setting a date, without specifying the time zone, JavaScript will use the browser's time zone.
  • 16. WARNINGS !  In some browsers, months or days with no leading zeroes may produce an error: Example: var d = new Date("2015-3-25"); -----------------------------------------------------------------------------------  The behavior of "YYYY/MM/DD" is undefined. Some browsers will try to guess the format. Some will return NaN. Example: var d = new Date("2015/03/25"); ------------------------------------------------------------------------------------  The behavior of "DD-MM-YYYY" is also undefined. Some browsers will try to guess the format. Some will return NaN. Example: var d = new Date("25-03-2015");
  • 17. DATE INPUT - PARSING DATES If you have a valid date string, you can use the Date.parse() method to convert it to milliseconds. Date.parse() returns the number of milliseconds between the date and January 1, 1970: Example: var msec = Date.parse("March 21, 2012"); document.getElementById("demo").innerHTML = msec; Output: 1332268200000
  • 18. JAVASCRIPT GET DATE METHODS Method Description getFullYear() Get the year as a four digit number (yyyy) getMonth() Get the month as a number (0-11) getDate() Get the day as a number (1-31) getHours() Get the hour (0-23) getMinutes() Get the minute (0-59) getSeconds() Get the second (0-59) getMilliseconds() Get the second (0-59) getTime() Get the time (milliseconds since January 1, 1970) getDay() Get the weekday as a number (0-6) Date.now() Get the time. ECMAScript 5.
  • 19. THE GETFULLYEAR() METHOD The getFullYear() method returns the year of a date as a four digit number: Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getFullYear(); Output: 2019
  • 20. THE GETMONTH() METHOD The getMonth() method returns the month of a date as a number (0,11): Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getMonth(); Output: 3
  • 21. THE GETDATE() METHOD The getDate() method returns the day of a data as a number(1-31): Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getDate(); Output: 11
  • 22. THE GETHOURS() METHOD The getHours() method returns the hours of a date as a number (0-23): Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getHours(); Output: 23
  • 23. THE GETMINUTES() METHOD The getMinutes() method returns the minutes of a date as a number (0-59): Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getMinutes(); Output: 7
  • 24. THE GETSECONDS() METHOD The getSeconds() method returns the seconds of a date as a number (0-59): Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getSeconds(); Output: 22
  • 25. THE GETMILLISECONDS() METHOD The getMilliseconds() method returns the milliseconds of a date as a number (0-999): Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getMilliseconds(); Output: 661
  • 26. THE GETDAY() METHOD The getDay() method returns the weekday of a date as a number (0-6): Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getDay(); Output: 6 Note: In JavaScript, the first day of the week (0) means "Sunday", even if some countries in the world consider the first day of the week to be "Monday"
  • 27. You can use an array of names, and getDay() to return the weekday as a name: Example: var d = new Date(); var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; document.getElementById("demo").innerHTML = days[d.getDay()]; Output: Wednesday
  • 28. THE GETTIME() METHOD The getTime() method returns the number of milliseconds since January 1, 1970: Example: var d = new Date(); document.getElementById("demo").innerHTML = d.getTime(); Output: 1551893921931
  • 29. UTC DATE METHODS UTC date methods are used for working with UTC dates (Universal Time Zone dates): Method Description getUTCDate() Same as getDate(), but returns the UTC date getUTCDay() Same as getDay(), but returns the UTC day getUTCFullYear() Same as getFullYear(), but returns the UTC Year getUTCHours() Same as getHours(), but returns the UTC hours getUTCMillisecond() Same as getMilliseconds(), but returns the UTC Millisecond getUTCMinutes() Same as getMinutes(), but returns the UTC Minutes getUTCMonth() Same as getMonth(), but returns the UTC Month getUTCSecond() Same as getSecond(), but returns the UTC Seconds