diff --git a/README.md b/README.md index 7a6d66d..86b1a2d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1167 TILs and counting..._ +_1168 TILs and counting..._ --- @@ -900,6 +900,7 @@ _1167 TILs and counting..._ - [Comparing Class Hierarchy Relationships](ruby/comparing-class-hierarchy-relationships.md) - [Comparing Arrays In RSpec](ruby/comparing-arrays-in-rspec.md) - [Construct A Constant From A String](ruby/construct-a-constant-from-a-string.md) +- [Convert A Unix Epoch Timestamp To A Time Object](ruby/convert-a-unix-epoch-timestamp-to-a-time-object.md) - [Create an Array of Stringed Numbers](ruby/create-an-array-of-stringed-numbers.md) - [Create a CSV::Table Object](ruby/create-a-csv-table-object.md) - [Create A Hash From An Array Of Arrays](ruby/create-a-hash-from-an-array-of-arrays.md) diff --git a/ruby/convert-a-unix-epoch-timestamp-to-a-time-object.md b/ruby/convert-a-unix-epoch-timestamp-to-a-time-object.md new file mode 100644 index 0000000..0c8b7a7 --- /dev/null +++ b/ruby/convert-a-unix-epoch-timestamp-to-a-time-object.md @@ -0,0 +1,18 @@ +# Convert A Unix Epoch Timestamp To A Time Object + +Ruby's `Time` class has an [`#at` +method](https://ruby-doc.org/core-2.6.3/Time.html#method-c-at) that allows you +get the _time_ at a certain unix epoch timestamp. That timestamp is an integer +value representing the number of seconds since the unix epoch. While it is a +handy way to store that data, it is hard to tell what time it represents at a +glance. + +```ruby +Time.at(1669652477) +=> 2022-11-28 10:21:17 -0600 +``` + +Using `Time.at` we are able to turn that integer into a `Time` object that +represents the date and time in a human-readable way. + +[source](https://prathamesh.tech/2020/03/02/converting-timestamps-to-ruby-objects/)