{"id":17689178,"url":"https://github.com/othyn/datestrings","last_synced_at":"2026-03-03T21:32:08.110Z","repository":{"id":84632613,"uuid":"273758088","full_name":"othyn/DateStrings","owner":"othyn","description":"A Swift 5 Date extension library that adds helpful string accessors and a string based initialiser. With new methods and properties that make getting a string from a Date easy.","archived":false,"fork":false,"pushed_at":"2020-10-05T19:19:14.000Z","size":35948,"stargazers_count":7,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-19T17:47:57.181Z","etag":null,"topics":["date","extension","extensions","helper","helpers","ios","ios-swift","libraries","library","package","string","swift","swift-package","swift-package-manager","swift5"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/othyn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-20T17:53:44.000Z","updated_at":"2023-05-19T00:51:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"5702e750-9f20-4008-828d-129bd98ae5e4","html_url":"https://github.com/othyn/DateStrings","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/othyn/DateStrings","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2FDateStrings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2FDateStrings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2FDateStrings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2FDateStrings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/othyn","download_url":"https://codeload.github.com/othyn/DateStrings/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/othyn%2FDateStrings/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30062411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["date","extension","extensions","helper","helpers","ios","ios-swift","libraries","library","package","string","swift","swift-package","swift-package-manager","swift5"],"created_at":"2024-10-24T11:46:47.062Z","updated_at":"2026-03-03T21:32:08.055Z","avatar_url":"https://github.com/othyn.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🗓 DateStrings\n\n[![Build and Tests](https://github.com/othyn/DateStrings/workflows/Build%20and%20Tests/badge.svg)](https://github.com/othyn/DateStrings/actions?query=workflow%3A%22Build+and+Tests%22)\n[![Code Coverage](https://img.shields.io/badge/Code%20Coverage-100%25-blueviolet)](https://github.com/othyn/DateStrings/actions?query=workflow%3A%22Build+and+Tests%22)\n[![GitHub issues](https://img.shields.io/github/issues/othyn/DateStrings)](https://github.com/othyn/DateStrings/issues)\n[![GitHub forks](https://img.shields.io/github/forks/othyn/DateStrings)](https://github.com/othyn/DateStrings/network)\n[![GitHub stars](https://img.shields.io/github/stars/othyn/DateStrings)](https://github.com/othyn/DateStrings/stargazers)\n[![GitHub license](https://img.shields.io/github/license/othyn/DateStrings)](https://github.com/othyn/DateStrings/blob/master/LICENSE)\n[![Quote](https://img.shields.io/badge/just-one%20more%20thing-lightgrey)](https://en.wikipedia.org/wiki/IPhone_(1st_generation))\n[![Love](https://img.shields.io/badge/built%20with-love-red)](https://img.shields.io/badge/built%20with-love-red)\n\nA Swift 5 `Date` extension library that adds helpful string accessors and a string based initialiser. With new methods and properties that make getting a string from a Date easy.\n\nLocale can be handled automatically (if not provided it's handled by the device) or manually (to ensure all devices present the same locale format).\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./Assets/preview.gif?raw=true\"\u003e\n\u003c/p\u003e\n\n## Table of contents\n\n- [Installation](#installation)\n  - [Adding via Xcode](#adding-via-xcode)\n  - [Adding via SPM Manually](#adding-via-spm-manually)\n- [Importing The Library Into Your Project](#importing-the-library-into-your-project)\n- [Usage](#usage)\n  - [Initialiser](#initialiser)\n  - [asString](#asString)\n    - [toString](#toString)\n  - [day](#day)\n  - [dayShort](#dayshort)\n  - [dayAsSingleDigit](#dayassingledigit)\n  - [dayAsDoubleDigit](#dayasdoubledigit)\n  - [month](#month)\n  - [monthShort](#monthshort)\n  - [monthAsSingleDigit](#monthassingledigit)\n  - [monthAsDoubleDigit](#monthasdoubledigit)\n  - [year](#year)\n  - [yearShort](#yearshort)\n  - [datestamp](#datestamp)\n  - [iso8601Python](#iso8601python)\n- [Building](#building)\n- [Testing](#testing)\n- [Useful Reference Material](#useful-reference-material)\n- [Changelog](#changelog)\n- [Versioning](#versioning)\n\n## Installation\n\nThis is Swift 5 package and makes use of Swift Package Manager (SPM) to integrate it into your Swift project.\n\nSwift Swift Swift.\n\n### Adding via Xcode\n\nAdd the package via the following menu's whilst in your Xcode project:\n\n```plaintext\nFile \u003e Swift Packages \u003e Add Package Dependency...\n```\n\nPaste this git repo URL into the search bar at the top:\n\n```url\nhttps://github.com/othyn/DateStrings.git\n```\n\nPress the enter key or `Next` and for the rules, if not automatically selected, select `Version` as `Up to Next Major`: `1.0.0` \u003c `2.0.0`.\n\nHit `Finish` once Xcode has downloaded and initialised the package to add it to your project.\n\n### Adding via SPM Manually\n\nAdd the following as a dependency to your `Package.swift` within your project directory:\n\n```swift\n.package(url: \"https://github.com/othyn/DateStrings.git\", .upToNextMajor(from: \"1.0.0\"))\n```\n\nAfter specifying \"DateStrings\" as a dependency of the target in which you want to use it, run swift package update.\n\n## Importing The Library Into Your Project\n\nAdd `import DateStrings` to the top of the file you wish to use the library in.\n\nThis package is an extension to the base `Date` object, with all methods and properties accessible via any inherited objects or the `Date` object itself.\n\n## Usage\n\n### Initialiser\n\nThere is a new initialiser that allows for quickly initialising a `Date` object from a date string. You can provide a custom format for the string.\n\nBy default, the locale will be the locale of the device that the app is being run on. You can stop this by passing a fixed locale string to the method as the `locale` parameter.\n\n```swift\ninit(fromString dateString: String, format: String = \"yyyy-MM-dd\", locale: String? = nil) { ... }\n```\n\nThis allows for the following to be used to create a `Date` instance object from a string.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n```\n\nThis also allows for passing in a custom format and/or a locale.\n\n```swift\nlet date = Date(fromString: \"2007-06-29 23:49:59\", format: \"yyyy-MM-dd HH:mm:ss\", locale: \"en_US_POSIX\")\n```\n\n### asString\n\nThis method allows you to get the date in a format of your choosing, from a `DateFormatter.Style` or a custom provided format and/or locale.\n\nBy default, the locale will be the locale of the device that the app is being run on. You can stop this by passing a fixed locale string to the method as the `locale` parameter.\n\n```swift\nfunc asString(inStyle style: DateFormatter.Style, locale: String? = nil) -\u003e String { ... }\n\nfunc asString(inFormat format: String, locale: String? = nil) -\u003e String { ... }\n```\n\nAn example of the `inStyle` usage:\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet dateFullString = date.asString(inStyle: .full)\n\n...\n\nText(dateFullString) // Friday, June 29, 2007\n```\n\nAn example of the `inFormat` usage:\n\n```swift\nlet date = Date(fromString: \"2007-06-29 23:49:59\", format: \"yyyy-MM-dd HH:mm:ss\")\n\nlet dateCustomString = date.asString(inFormat: \"yyyy-MM-dd HH:mm:ss\")\n\n...\n\nText(dateCustomString) // 2007-06-29 23:49:59\n```\n\n#### toString\n\nThere is also an alternative syntax `toString`, which mirrors the `asString` methods exactly (uses them internally too, just maps the functions forward). Just a personal preference of naming on this one. As in, use it if you prefer the `toString` method names.\n\n\nAn example of the `inStyle` usage:\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet dateFullString = date.toString(inStyle: .full)\n\n...\n\nText(dateFullString) // Friday, June 29, 2007\n```\n\nAn example of the `inFormat` usage:\n\n```swift\nlet date = Date(fromString: \"2007-06-29 23:49:59\", format: \"yyyy-MM-dd HH:mm:ss\")\n\nlet dateCustomString = date.toString(inFormat: \"yyyy-MM-dd HH:mm:ss\")\n\n...\n\nText(dateCustomString) // 2007-06-29 23:49:59\n```\n\n### day\n\nA helpful computed property for getting the day from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet day = date.day\n\n...\n\nText(day) // Friday\n```\n\n### dayShort\n\nA helpful computed property for getting the short day from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet day = date.dayShort\n\n...\n\nText(day) // Fri\n```\n\n### dayAsSingleDigit\n\nA helpful computed property for getting the single digit day from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-05\")\n\nlet day = date.dayAsSingleDigit\n\n...\n\nText(day) // 5\n```\n\n### dayAsDoubleDigit\n\nA helpful computed property for getting the double digit day from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-05\")\n\nlet day = date.dayAsDoubleDigit\n\n...\n\nText(day) // 05\n```\n\n### month\n\nA helpful computed property for getting the month from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet month = date.month\n\n...\n\nText(month) // June\n```\n\n### monthShort\n\nA helpful computed property for getting the short month from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet month = date.monthShort\n\n...\n\nText(month) // Jun\n```\n\n### monthAsSingleDigit\n\nA helpful computed property for getting the single digit month from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet month = date.monthAsSingleDigit\n\n...\n\nText(month) // 6\n```\n\n### monthAsDoubleDigit\n\nA helpful computed property for getting the double digit month from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet month = date.monthAsDoubleDigit\n\n...\n\nText(month) // 06\n```\n\n### year\n\nA helpful computed property for getting the year from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet year = date.year\n\n...\n\nText(year) // 2007\n```\n\n### yearShort\n\nA helpful computed property for getting the short year from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29\")\n\nlet year = date.yearShort\n\n...\n\nText(year) // 07\n```\n\n### datestamp\n\nA helpful computed property for getting the datestamp from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29 10:00:00\", format: \"yyyy-MM-dd HH:mm:ss\")\n\nlet datestamp = date.datestamp\n\n...\n\nText(datestamp) // 2007-06-29 10:00:00\n```\n\n### iso8601Python\n\nA helpful computed property for getting the ISO 8601 Python format from the `Date`.\n\n```swift\nlet date = Date(fromString: \"2007-06-29 10:00:00\", format: \"yyyy-MM-dd HH:mm:ss\")\n\nlet iso8601Python = date.iso8601Python\n\n...\n\nText(iso8601Python) // 2007-06-29T10:00:00.000\n```\n\n## Building\n\nTo build, use Xcode's standard build tools via `⌘ + B` or use the `swift` CLI command in the project root directory:\n\n```sh\nswift build\n```\n\n## Testing\n\nTo run the tests, use Xcode's standard test tools via `⌘ + U` or use the `swift` CLI command in the project root directory:\n\n```sh\nswift test\n```\n\n## Useful Reference Material\n\nBelow are some really useful references that I found when building this extension Library to aid with date formatting and converting\nformats.\n\nEspecially as Apple don't really document this themselves anywhere. Although if someone does find it, please submit a PR and\ncorrect me.\n\n- A website that allows you to put in a date format and test date formats inline with DateFormatter and NSDateFormatter:\n  - [https://nsdateformatter.com/](https://nsdateformatter.com/)\n  - (It also has a really handy reference/cheat sheet for all the character strings)\n- Useful SO posts regarding date formats for DateFormatter and NSDateFormatter that I stumbled upon originally:\n  - [https://stackoverflow.com/a/52297497/4494375](https://stackoverflow.com/a/52297497/4494375)\n  - [https://stackoverflow.com/a/43821434/4494375](https://stackoverflow.com/a/43821434/4494375)\n  - [https://stackoverflow.com/a/48179960/4494375](https://stackoverflow.com/a/48179960/4494375)\n  - [https://stackoverflow.com/a/24090354/4494375](https://stackoverflow.com/a/24090354/4494375)\n\nThere is also [something to note](https://stackoverflow.com/q/27321993/4494375) around how creating `NSDateFormatter` and\n`DateFormatter` are an [expensive operation](https://stackoverflow.com/q/27321993/4494375), with Apple even stating so in their\n2014 docs. If anyone has any ways to optimise this, I'm all ears. I've tried to be as performant as possible to what I know.\n\nThere is also an easter egg in the library for funsies, [if you know what to look for](https://en.wikipedia.org/wiki/IPhone_(1st_generation)).\n\n## Changelog\n\n[View the repo's releases to see the change history](https://github.com/othyn/DateStrings/releases).\n\n## Versioning\n\n[This project uses Semantic Versioning](https://semver.org/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothyn%2Fdatestrings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fothyn%2Fdatestrings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fothyn%2Fdatestrings/lists"}