- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a Date object and what all parameters it include?
59 Lectures 8.5 hours
68 Lectures 8 hours
Once a Date object is created, a number of methods allow you to operate on it. Most methods simply allow you to get and set the year, month, day, hour, minute, second, and millisecond fields of the object, using either local time or UTC (universal, or GMT) time.
You can use any of the following syntaxes to create a Date object using Date() constructor −
new Date( ) new Date(milliseconds) new Date(datestring) new Date(year,month,date[,hour,minute,second,millisecond ])
The following is the description of parameters −
- No Argument − With no arguments, the Date() constructor creates a Date object set to the current date and time.
- milliseconds − When one numeric argument is passed, it is taken as the internal numeric representation of the date in milliseconds, as returned by the getTime() method. For example, passing the argument 5000 creates a date that represents five seconds past midnight on 1/1/70.
- datestring − When one string argument is passed, it is a string representation of a date, in the format accepted by the Date.parse() method.
- 7 agruments − To use the last form of the constructor shown above. Here is a description of each argument −
- year − Integer value representing the year. For compatibility (in order to avoid the Y2K problem), you should always specify the year in full; use 1998, rather than 98.
- month − Integer value representing the month, beginning with 0 for January to 11 for December.
- date − Integer value representing the day of the month.
- hour − Integer value representing the hour of the day (24-hour scale).
- minute − Integer value representing the minute segment of a time reading.
- second − Integer value representing the second segment of a time reading.
- millisecond − Integer value representing the millisecond segment of a time reading.
- How to create date object in Java?
- How do you create a date object from a date in Swift xcode?
- How to include an embedded object in HTML?
- How to convert a Python date string to a date object?
- How to convert a JS Date to a Python date object?
- How do you create a date object from a date in Swift xcode in iOS?
- How to create Date object from String value in Java?
- How to read all form parameters in JSP?
- How to convert a Date object to LocalDate object in java?
- Create a Date object using the Calendar class in Java
- How to create a new object and get its saved object in MongoDB?