Git Product home page Git Product logo

date_format's Introduction

DateFormat

DateFormat is the gem used to access formatted datetime. The library take raw date as input and adds a method to give formatted date. By using same gem, user can find the date difference from start date to end date in different format like seconds, minutes, hours, days, months and years.

Installation

Add this line to your application's Gemfile:

gem 'date_format'

And then execute:

$ bundle

Or install it yourself as:

$ gem install date_format

Usage

Try this snippet of code on ruby irb

require 'date_format'
today_time = Time.now
puts DateFormat.change_to(today_time, "GENERAL_DATE")                       # => 10/11/14 05:12:26 PM
puts DateFormat.change_to(today_time, "LONG_DATE")                          # => Saturday, October 11, 2014
puts DateFormat.change_to(today_time, "ISO_8601_FORMAT")                    # => 2014-10-11
puts DateFormat.change_to(today_time, "MEDIUM_DATE")                        # => 11-Oct-2014
puts DateFormat.change_to(today_time, "SHORT_DATE")                         # => 10/11/14 (mm/dd/yy)
puts DateFormat.change_to(today_time, "LONG_TIME")                          # => 05:12:26 PM
puts DateFormat.change_to(today_time, "MEDIUM_TIME")                        # => 17:12 PM
puts DateFormat.change_to(today_time, "SHORT_TIME")                         # => 17:12
puts DateFormat.change_to(today_time, "WEEK_OF_YEAR")                       # => 40
puts DateFormat.change_to(today_time, "DAY_IN_MONTH")                       # => 11
puts DateFormat.change_to(today_time, "JULIAN_DAY")                         # => 2014
puts DateFormat.change_to(today_time, "ONLY_HOUR_IN_24HOUR_FORMAT")         # => 17
puts DateFormat.change_to(today_time, "HOURS_IN_24HOUR_FORMAT")             # => 17:12
puts DateFormat.change_to(today_time, "MINUTE_IN_HOUR")                     # => 12
puts DateFormat.change_to(today_time, "ONLY_DATE")                          # => October 11, 2014
puts DateFormat.change_to(today_time, "LONG_DATE_SHORT")                    # => Sat, October 11, 2014
puts DateFormat.change_to(today_time, "ONLY_DATE_DEFAULT")                  # => 11/10/2014 (dd/mm/yy)
puts DateFormat.change_to(today_time, "ONLY_DATE_SHORT")                    # => Oct 11, 2014
puts DateFormat.change_to(today_time, "ONLY_DATE_SHORTEST")                 # => Sat, Oct 11, 2014
puts DateFormat.change_to(today_time, "")                                   # => 11.10.14
puts DateFormat.change_to(today_time, "ONLY_CURRENT_DATE_NUMBER")           # => 11
puts DateFormat.change_to(today_time, "ONLY_CURRENT_DATE_ALPHABET")         # => Sat
puts DateFormat.change_to(today_time, "ONLY_CURRENT_MONTH_NUMBER")          # => 10
puts DateFormat.change_to(today_time, "ONLY_CURRENT_MONTH_ALPHABET")        # => Oct
puts DateFormat.change_to(today_time, "ONLY_CURRENT_YEAR_MONTH")            # => 201410
puts DateFormat.change_to("", "")                                           # => NA

# For Time Difference
start_date = Time.parse('2014-05-25 18:37:11')
DateFormat.time_difference(start_date, "PRESENT_DAY", "DAY_ONLY")
DateFormat.time_difference(start_date, "PRESENT_DAY", "HOUR_ONLY")
DateFormat.time_difference(start_date, "PRESENT_DAY", "MINUTE_ONLY")
DateFormat.time_difference(start_date, "PRESENT_DAY", "SECOND_ONLY")
DateFormat.time_difference(start_date, "", "DAY_ONLY")
DateFormat.time_difference(start_date, "", "HOUR_ONLY")
DateFormat.time_difference(start_date, "", "MINUTE_ONLY")
DateFormat.time_difference(start_date, "", "SECOND_ONLY")
DateFormat.time_difference(start_date, "AA", "HOUR_ONLY")
DateFormat.time_difference(start_date, "XX", "MINUTE_ONLY")
DateFormat.time_difference(start_date, "DD", "SECOND_ONLY")

Contributing

  1. Fork it ( https://github.com/[my-github-username]/date_format/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

date_format's People

Contributors

rpatil avatar

Watchers

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