如何将unix时间戳(从epoch开始的秒)转换为Ruby DateTime? [英] How to convert a unix timestamp (seconds since epoch) to Ruby DateTime?

查看:150
本文介绍了如何将unix时间戳(从epoch开始的秒)转换为Ruby DateTime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Unix时间戳(从epoch开始的秒数)转换为Ruby DateTime?

How do you convert a Unix timestamp (seconds since epoch) to Ruby DateTime?

推荐答案

DateTime.strptime 可以处理从时代开始的秒数。数字必须转换为字符串:

DateTime.strptime can handle seconds since epoch. The number must be converted to a string:

require 'date'
DateTime.strptime("1318996912",'%s')

这篇关于如何将unix时间戳(从epoch开始的秒)转换为Ruby DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆