Ruby | DateTime strptime() function
DateTime#strptime() : strptime() is a DateTime class method which parses the given representation of date and time with the given template
Syntax: DateTime.strptime()
Parameter: DateTime values
Return: parses the given representation of date and time with the given template
Example #1 :
# Ruby code for DateTime.strptime() method # loading library require 'date' # declaring DateTime value date_a = DateTime.strptime('10-02-2015 05:05:06 PM', '%d-%m-%Y %I:%M:%S %p') # declaring DateTime value date_b = DateTime.strptime('2018 02 3 07 10 09 +7', '%Y %U %w %H %M %S %z') # strptime method puts "DateTime strptime form : #{date_a}\n\n" puts "DateTime strptime form : #{date_b}\n\n" |
chevron_right
filter_none
Output :
DateTime strptime form : 2015-02-10T17:05:06+00:00 DateTime strptime form : 2018-01-17T07:10:09+07:00
Example #2 :
# Ruby code for DateTime.strptime() method # Ruby code for DateTime.strptime() method # loading library require 'date' # declaring DateTime value date_a = DateTime.strptime('2010 04 6 04 05 06 +7', '%Y %U %w %H %M %S %z') # declaring DateTime value date_b = DateTime.strptime('-1', '%s') # strptime method puts "DateTime strptime form : #{date_a}\n\n" puts "DateTime strptime form : #{date_b}\n\n" |
chevron_right
filter_none
Output :
DateTime strptime form : 2010-01-30T04:05:06+07:00 DateTime strptime form : 1969-12-31T23:59:59+00:00
Recommended Posts:
- Ruby | DateTime sec() function
- Ruby | DateTime second() function
- Ruby | DateTime jd() function
- Ruby | DateTime now() function
- Ruby | DateTime new() function
- Ruby | DateTime parse() function
- Ruby | DateTime ordinal() function
- Ruby | DateTime rfc2822() function
- Ruby | DateTime httpdate() function
- Ruby | DateTime commercial() function
- Ruby | DateTime hour() function
- Ruby | DateTime jisx0301() function
- Ruby | DateTime iso8601() function
- Ruby | DateTime new_offset() function
- Ruby | DateTime offset() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


