Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Js Date Set Methods in JavaScript

Js Date Set Methods in JavaScript

?? JavaScript Date Set Methods


JavaScript’s Date object provides set methods to modify parts of a date/time.


Common Date Set Methods

MethodDescriptionParameter
setFullYear(year, [month], [date])Sets the full year, optionally month and dayyear (e.g., 2025), optional month (0–11), optional day (1–31)
setMonth(month, [date])Sets the month and optionally daymonth (0–11), optional day (1–31)
setDate(date)Sets the day of the monthdate (1–31)
setHours(hours, [min], [sec], [ms])Sets hours and optionally minutes, seconds, millisecondshours (0–23), optional minutes, seconds, ms
setMinutes(minutes, [sec], [ms])Sets minutes and optionally seconds, millisecondsminutes (0–59), optional seconds, ms
setSeconds(seconds, [ms])Sets seconds and optionally millisecondsseconds (0–59), optional ms
setMilliseconds(ms)Sets millisecondsms (0–999)
setTime(timestamp)Sets the time in milliseconds since Unix Epochtimestamp (number)

Examples

const date = new Date('2025-06-02T10:00:00');date.setFullYear(2030);date.setMonth(0);        // January (months are 0-based)date.setDate(15);date.setHours(9, 30);    // 9:30 AMdate.setMinutes(45);date.setSeconds(20);date.setMilliseconds(500);console.log(date.toISOString()); // Output: "2030-01-15T09:45:20.500Z"

Notes

  • If you set a value out of the expected range, the Date object will auto-adjust (e.g., setDate(32) moves to the next month).

  • Use setTime() to set the full timestamp at once.


Want me to show UTC set methods or examples of how to use these to manipulate dates?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql