GithubHelp home page GithubHelp logo

zch617 / nsdate-time-ago Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nikilster/nsdate-time-ago

0.0 2.0 0.0 504 KB

Implements Facebook's format for Time Ago (on their mobile apps)

License: Apache License 2.0

nsdate-time-ago's Introduction

Facebook Style Formatting of Dates (Time Ago)

I was really surprised that I couldn't find an iOS date formatter which implemented the Facebook style "Time Ago" format so I whipped one up myself. I reverse engineered the Facebook format, so this should be pretty accurate. Feel free to use it in your projects / improve it.

Hope you enjoy :)

If you have any questions feel free to contact me here: www.nikilster.com/about.html


## Date Format < 1 minute             =   "Just now"

< 1 hour                 = "x minutes ago"

Today                    = "x hours ago"

Yesterday              = "Yesterday at 1:28pm"

< Last 7 days         = "Friday at 1:48am"

< Last 30 days       = "March 30 at 1:14 pm"

< 1 year                 = "September 15"

Anything else         = "September 9, 2011"


About

  • This NSDate category adds the facebook style "time ago" date formatting.
  • This mimics Facebook mobile (the desktop version has slightly different date formatting).
  • This assumes all dates are in the past.

##To use this in your iOS project: 1. Drag both NSDate+NVTimeAgo.m aand NSDate+NVTimeAgo.h into your iOS project in XCode 2. In the files that you want to use this functionality in,itType:
    #import "NSDate+NVTimeAgo.h"

somewhere near the top of your file.
  1. Use the date formatter on a date by calling:

     [date formattedAsTimeAgo]
    

    where date is an (NSDate *) and represents a date IN THE PAST (relative to now).

    If you have a mysql datetime string and you want to convert it to the time ago format, do:

     NSString *mysqlDatetime = <Get from the database>
     NSString *timeAgoFormattedDate = [NSDate mysqlDatetimeFormattedAsTimeAgo:mysqlDatetime];`
    

Created By

Nikil Viswanathan on 4/18/2013

You can contact me on: www.nikilster.com


## Credits Thanks to dellinger for making it into a CocoaPod.

nsdate-time-ago's People

Contributors

david-ellinger avatar nikilster avatar

Watchers

James Cloos avatar  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.