Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

date_format

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

date_format

  • 0.3.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 29 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc