rails中的时间显示格式

简介:
在rails中需要显示时间时,格式化时间的方法一般选用strftime,下面是关于strftime的一些介绍

strftime Format Codes

Year

Example
%Y year with century 2007
%y year without century 07
%C century number (year divided by 100) 20
 

Month

Example
%B full month name January
%b abbreviated month name Jan
%h same as %b Jan
%m month as number (01-12)
 

Week

Example
%U week number of the year, Sunday as first day of week (00-53)
%W week number of the year, Monday as first day of week (00-53)
 

Day

Example
%A full weekday name Wednesday
%a abbreviated weekday name Wed
%d day of the month (01-31)
%e day of the month, single digits preceded by space ( 1-31)
%j day of the year (001-366)
%w weekday as a number, with 0 representing Sunday (0-6)
%u weekday as a number, with 1 representing Monday (1-7)
 

Time

Example
%H hour (24-hour clock) (00-23)
%k hour (24-hour clock); single digits preceded by space ( 0-23)
%I hour (12-hour clock) (01-12)
%l hour (12-hour clock); single digits preceded by space ( 1-12)
%M minute (00-59)
%S seconds (00-59)
%p either AM or PM AM
%Z timezone name or abbreviation EDT
%z timezone offset from UTC -0400
 

Summaries

Example
%D date, same as %m/%d/%y 05/16/07
%v date, same as %e-%b-%Y 16-May-2007
%F date, same as %Y-%m-%d 2007-05-16
%R time, 24 hour notation, same as %H:%M 18:06
%T time, 24 hour notation, same as %H:%M:%S 18:06:15
%r time, am/pm notation, same as %I:%M:%S %p 06:06:15 PM
 

Formatting

%n newline character
%t tab character
%% percent character
 

Less common formats

%s number of seconds since the Epoch, UTC
%c national date and time representation
%+ national date and time representation
%x national date representation
%X national time representation
%G year with century, starting on first Monday where week has 4 or more days.
%g year without century, starting on first Monday where week has 4 or more days.
%V week number of the year, starting on first Monday where week has 4 or more days.





本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/114411,如需转载请自行联系原作者
目录
相关文章
|
2月前
|
运维 大数据 Shell
时间命令date,你真的会用了吗?
时间命令date,你真的会用了吗?
42 0
|
存储 PHP 数据库
Laravel-admin实现时间戳和自定义日期的自动转换
今天介绍我在使用laravel-admin遇到的坑,我数据库存储的时间是int类型的时间戳,需要在管理后台展示日期怎么优雅的实现呢?
1129 0
Laravel-admin实现时间戳和自定义日期的自动转换
SwiftUI—方便用户选择日期的DatePicker日期拾取器
SwiftUI—方便用户选择日期的DatePicker日期拾取器
1428 0
SwiftUI—方便用户选择日期的DatePicker日期拾取器
|
存储 Java 测试技术
JMeter 内置日期(时间)函数总结
JMeter 内置日期(时间)函数总结
130 0
|
JavaScript 前端开发 数据格式
Ant Design Vue 日期选择器,绑定的日期和框内不一致,日期格式化,纠正时差
Ant Design Vue 日期选择器,绑定的日期和框内不一致,日期格式化,纠正时差
760 0
Ant Design Vue 日期选择器,绑定的日期和框内不一致,日期格式化,纠正时差
|
Java API Spring
freemarker 时间显示不正常 设置时区
项目在本地开发的时候显示正常,部署上服务器就一直差8个小时,最后发现freemarker官方文档有这样的说明
235 0
|
Java Android开发
Eclipse设置日期和时间格式自定义
Eclipse设置日期和时间格式自定义
311 0
Eclipse设置日期和时间格式自定义
|
数据库 Windows Python
Django 时间与时区设置
再写入数据库对时间进行加减操作时候 django报告了错误 TypeError: can't subtract offset-naive and offset-aware datetimes 修改setting.py 文件 在Django的配置文件settings.py中,有两个配置参数是跟时间与时区有关的, 分别是TIME_ZONE和USE_TZ 如果USE_TZ设置为True时,Django会使用系统默认设置的时区,即America/Chicago, 此时的TIME_ZONE不管有没有设置都不起作用。
1816 0
|
Java 自然语言处理
Confluence 6 配置时间和日期格式
你可以修改你 Confluence 为用户显示的时期和时间格式。设置的句法使用的是 SimpleDateFormat class,请参考 Java SimpleDateFormat 文档中的内容来设置日期和时间格式。
1207 0