SetDate



The setDate() method changes the day of the month of a given Date instance, based on local time.

  1. Set Date
  2. Set Date In Linux
  3. Setdateformat Java

To instead change the day of the month for a given Date instance based on UTC time, use the setUTCDate() method.

Syntax

Set Date

Parameters

  1. JavaScript setDate 方法 JavaScript Date 对象 实例 设置一个月的某一天: var d = new Date; d.setDate(15); d 输出结果: var d = new Date d.setDate(15) document.write(d) 尝试一下 » 定义和用法 setDate 方法用于设置一个月的某一天。 浏览器支持 所有主要浏览器都支.
  2. SetDate public method. Private void controlMouseDown(object sender, System.Windows.Forms.MouseEventArgs e) ControlFactory factory = ControlFactory. Instance; if ( e. Button MouseButtons. Left) Field field = factory.GetAssociatedField(( Control) sender); if ( field!= null) control = ( Control) sender; if ( field is DateField field.
  3. Date.prototype.setDate Die setDate Methode setzt den Tag eines Date Objektes relativ zum Beginn des aktuellen Monats. The source for this interactive example is stored in a GitHub repository.
dayValue
An integer representing the day of the month.

The date.setDate method is used to set date of a month into a date object which are created using date constructor.

Return value

The number of milliseconds between 1 January 1970 00:00:00 UTC and the given date (the Date object is also changed in place).

Description

If the dayValue is outside of the range of date values for the month, setDate() will update the Date object accordingly.

For example, if 0 is provided for dayValue, the date will be set to the last day of the previous month.

If a negative number is provided for dayValue, the date will be set counting backwards from the last day of the previous month. -1 would result in the date being set to 1 day before the last day of the previous month.

Examples

Using setDate()

Specifications

Specification
ECMAScript (ECMA-262)
The definition of 'Date.prototype.setDate' in that specification.

Browser compatibility

BCD tables only load in the browser

See also

Setdate function -->

Changes the system time on the computer to a time that you specify.

Syntax

Description

The Set-Date cmdlet changes the system date and time on the computer to a date and time that youspecify.You can specify a new date and/or time by typing a string or by passing a DateTime orTimeSpan object to Set-Date. To specify a new date or time, use the Date parameter.To specify a change interval, use the Adjust parameter.

Examples

Example 1: Add three days to the system date

This command adds three days to the current system date.It does not affect the time.The command uses the Date parameter to specify the date.

The Get-Date cmdlet returns the current date as a DateTime object. The DateTime object'sAddDays method adds a specified number of days (3) to the current DateTime object.

Example 2: Set the system clock back 10 minutes

This example sets the current system time back by 10 minutes.

The Adjust parameter allows you to specify an interval of change (minus ten minutes) in thestandard time format for the locale.

The DisplayHint parameter tells PowerShell to display only the time, but it does notaffect the DateTime object that Set-Date returns.

Example 3: Set the date and time to a variable value

These commands change the system date and time on local computer to the date and time saved in thevariable $T. The first command gets the date and stores it in $T.

The second command uses the Date parameter to pass the DateTime object in $T to theSet-Date cmdlet.

Example 4: Add 90 minutes to the system clock

These commands advance the system time on the local computer by 90 minutes.

The first command uses the New-TimeSpan cmdlet to create a TimeSpan object with a 90-minuteinterval, and saves it in the $90mins variable.

The second command uses the Adjust parameter of Set-Date to adjust the date by the value ofthe TimeSpan object in the $90mins variable.

Parameters

Specifies the value for which this cmdlet adds or subtracts from the current date and time.can type an adjustment in standard date and time format for your locale or use the Adjustparameter to pass a TimeSpan object from New-TimeSpan to Set-Date.

Type:TimeSpan
Position:0
Default value:None
Accept pipeline input:True
Accept wildcard characters:False

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Changes the date and time to the specified values.You can type a new date in the short date format and a time in the standard time format for yourlocale. Or, you can pass a DateTime object from Get-Date.

If you specify a date, but not a time, Set-Date changes the time to midnight on the specifieddate. If you specify only a time, it does not change the date.

Type:DateTime
Position:0
Default value:None
Accept pipeline input:True
Accept wildcard characters:False
Set

Specifies which elements of the date and time are displayed.The acceptable values for this parameterare:

  • Date - displays only the date.
  • Time - displays only the time.
  • DateTime - displays the date and time.

This parameter affects only the display.It does not affect the DateTime object that Get-Date retrieves.

Type:DisplayHintType
Accepted values:Date, Time, DateTime
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Set Date In Linux

SetDate

Shows what would happen if the cmdlet runs.The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

You can pipe a date to Set-Date.

Setdateformat Java

Outputs

Set-Date returns an object that represents the date that it set.

Notes

  • Use this cmdlet cautiously when changing the date and time on the computer. The change mightprevent the computer from receiving system-wide events and updates that are triggered by a date ortime. Use the WhatIf and Confirm parameters to avoid errors.

  • You can use standard .NET methods with the DateTime and TimeSpan objects used withSet-Date, such as AddDays, AddMonths, and FromFileTime. For more information, seeDateTime Methods and

    TimeSpan Methods in the .NET SDK.

Related Links