---
title: "date(with:)"
framework: foundation
role: symbol
role_heading: Type Method
path: "foundation/nsdate/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).

## Declaration

```swift
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

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

## Discussion

Discussion To create a date object from a string, you should typically use a date formatter object instead (see DateFormatter and Data Formatting Guide).

## See Also

### Legacy Operations

- [date(withNaturalLanguageString:)](foundation/nsdate/date(withnaturallanguagestring:).md)
- [date(withNaturalLanguageString:locale:)](foundation/nsdate/date(withnaturallanguagestring:locale:).md)
- [init(string:)](foundation/nsdate/init(string:).md)
- [addTimeInterval(_:)](foundation/nsdate/addtimeinterval(_:).md)
- [date(withCalendarFormat:timeZone:)](foundation/nsdate/date(withcalendarformat:timezone:).md)
- [description(withCalendarFormat:timeZone:locale:)](foundation/nsdate/description(withcalendarformat:timezone:locale:).md)
