<!--
{
  "availability" : [
    "iOS: 2.0.0 - 8.0.0",
    "iPadOS: 2.0.0 - 8.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.4.0 - 10.10.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDate/date(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDate(cm)dateWithString:"
  },
  "title" : "date(with:)"
}
-->

# date(with:)

Creates and returns a date object with a date and time value specified by a given string in the international string representation format (`YYYY-MM-DD HH:MM:SS ±HHMM`).

```
class func date(with aString: String) -> Any
```

## Parameters

`aString`

A string that specifies a date and time value in the international string representation format—`YYYY-MM-DD HH:MM:SS ±HHMM`, where `±HHMM` is a time zone offset in hours and minutes from UTC (for example, “`2001-03-24 10:45:32 +0600`”).

    You must specify all fields of the format string, including the time zone offset, which must have a plus or minus sign prefix.

## Return Value

An `NSDate` object with a date and time value specified by `aString`.

## Discussion

To create a date object from a string, you should typically use a date formatter object instead (see [`DateFormatter`](/documentation/Foundation/DateFormatter) and [Data Formatting Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/DataFormatting/DataFormatting.html#//apple_ref/doc/uid/10000029i)).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)