get milliseconds since 1970 from string
DateTime.parse("2016-08-12 06:13:24 UTC").strftime('%Q')
Get first 3 integer
in rails console
How do i print the date and time of specific lines that contain a certain key word using Ruby?
One way to do it would be like so (within a block that's iterating over the lines in the file, obviously):
Since the date information (which is what you want output) appears in the same position and is the same length in every line, we don't bother doing any parsing of the text for the output - just spit out the first 15 characters.
I'm tempted to try to compress all of this into a single regular expression, but this ought to work. Obviously, you could do something other than print out the date within the conditional, and if you wanted to work with it as a date, you could pass it to
DateTime.parse() (just remember to
require 'date' first).
jsTime = 1252268867928
# Sun Sep 06 20:27:47 +0000 2009
Ensuring a unique number to identify something
If you need unique identifier, you should make such. For example,
p SecureRandom.uuid #=> "2d931510-d99f-494a-8c67-87feb05e1594"
(I assume that PayPal accepts arbitrary strings and doesn't require actual integers)