当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Ruby DateTime second_fraction()用法及代码示例


DateTime#second_fraction():second_fraction()是DateTime类方法,该方法返回second.second_fraction的小数部分。

用法:DateTime.second_fraction()

参数:日期时间值


返回:秒的小数部分。

示例1:

# Ruby code for DateTime.second_fraction() method 
  
# loading library 
require 'date'
  
# declaring DateTime value 
date_a = DateTime.new(2019, 8, 10, 4, 10, 9) 
  
# declaring DateTime value 
date_b = DateTime.new(2019, 8, 10.5) 
  
# declaring DateTime value 
date_c = DateTime.new(2019, 8, 10, 4, 10, 9, Rational(4, 24)) 
  
  
#  second_fraction method 
puts "DateTime second_fraction form : #{date_a.second_fraction}\n\n"
  
puts "DateTime second_fraction form : #{date_b.second_fraction}\n\n"
  
puts "DateTime second_fraction form : #{date_c.second_fraction}\n\n"

输出:

DateTime second_fraction form : 0/1

DateTime second_fraction form : 0/1

DateTime second_fraction form : 0/1

示例2:

# Ruby code for DateTime.second_fraction() method 
  
# loading library 
require 'date'
  
# declaring DateTime value 
date_a = DateTime.new(2019, 8, 10, 5) 
  
# declaring DateTime value 
date_b = DateTime.parse('10 Aug 2018 04:10:06+04:30') 
  
# declaring DateTime value 
date_c = DateTime.new(2019, 8, 10, 4, 10, 9, '+03:00') 
  
  
#  second_fraction method 
puts "DateTime second_fraction form : #{date_a.second_fraction}\n\n"
  
puts "DateTime second_fraction form : #{date_b.second_fraction}\n\n"
  
puts "DateTime second_fraction form : #{date_c.second_fraction}\n\n"

输出:

DateTime second_fraction form : 0/1

DateTime second_fraction form : 0/1

DateTime second_fraction form : 0/1



相关用法


注:本文由纯净天空筛选整理自mayank5326大神的英文原创作品 Ruby | DateTime second_fraction() function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。