Coder Social home page Coder Social logo

mobilliumdateformatter's Introduction

MobilliumDateFormatter

Build Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 9.0+
  • Swift 5.0+

Installation

MobilliumDateFormatter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MobilliumDateFormatter'

Usage

MobilliumDateFormatter comes with these formats:

/// 2-digit year
/// Example: 08
case yy

/// 4-digit year
/// Example: 2008
case yyyy

/// The quarter of the year. Use QQ if you want zero padding.
/// Example: 4
case Q

/// Quarter including "Q"
/// Example: Q4
case QQQ

/// Quarter spelled out
/// Example: 4th quarter
case QQQQ

/// The numeric month of the year. A single M will use '1' for January.
/// Example: 12
case M

/// The numeric month of the year. A double M will use '01' for January.
/// Example: 12
case MM

/// The shorthand name of the month
/// Example: Dec
case MMM

/// Full name of the month
/// Example: December
case MMMM

/// Narrow name of the month
/// Example: D
case MMMMM

/// The day of the month. A single d will use 1 for January 1st.
/// Example: 14
case d

/// The day of the month. A double d will use 01 for January 1st.
/// Example: 14
case dd

/// The day of week in the month
/// Example: 3rd Tuesday in December
case F

/// The day of week in the month
/// Example: Tues
case E

/// The full name of the day
/// Example: Tuesday
case EEEE

/// The narrow day of week
/// Example: T
case EEEEE

/// The 12-hour hour.
/// Example: 4
case h

/// The 12-hour hour padding with a zero if there is only 1 digit
/// Example: 04
case hh

/// The 24-hour hour.
/// Example: 16
case H

/// The 24-hour hour padding with a zero if there is only 1 digit.
/// Example: 16
case HH

/// AM / PM for 12-hour time formats
/// Example: PM
case a

/// The minute, with no padding for zeroes.
/// Example: 35
case m

/// The minute with zero padding.
/// Example: 35
case mm

/// The seconds, with no padding for zeroes.
/// Example: 8
case s

/// The seconds with zero padding.
/// Example: 08
case ss

or Create your format:

import MobilliumDateFormatter

extension Date.Format {
    static let dateTime = Date.Format.custom(rawValue: "yyyy-MM-dd HH:mm:ss")
}

Set locale(optional):

MobilliumDateFormatter.locale = Locale(identifier: "us")

Set calendar(optional), default: Calendar.current:

MobilliumDateFormatter.calendar = Calendar.current

String to Date:

let dateString = "2001-01-01 01:01:00"
let date = Date.from(dateString, format: .dateTime)

Date to String:

let date = Date()
let dateString = date.to(.MMMM)

TimeInterval to Date:

let timeInterval = TimeInterval(exactly: 1549611277)!
let date = Date.from(timeInterval)

supported date component types for math operations:

enum DateComponentType {
    case year
    case month
    case weekOfYear
    case day
    case hour
    case minute
    case second
    case millisecond
}

example of adding days(you can add another date component type like this):

let date = Date()
let newDate = date.add(.day, count: 1)
// or
let newDate = now.addDay(-1)

License

MobilliumDateFormatter is available under the MIT license. See the LICENSE file for more info.

mobilliumdateformatter's People

Contributors

alihanaktay avatar aslanmehmetsalih avatar emirhanacisu avatar emirhanbattalbas avatar mrtcelebi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.