ruby中将数字转化为字符串格式时差
class Numeric
def duration_as_str
rest, secs = self.divmod( 60 )
rest, mins = rest.divmod( 60 )
days, hours = rest.divmod( 24 )
result = []
result << "#{days}天" if days > 0
result << "#{hours}小时" if hours > 0
result << "#{mins}分" if mins > 0
result << "#{secs}秒" if secs > 0
result.blank? ? "1秒" : result.join(' ') end
end 57423.duration_as_str
=> "15小时 57分 3秒"
ruby中将数字转化为字符串格式时差的更多相关文章
- 在Excel中将数字设置成文本格式的技巧
在Excel中将数字设置成文本格式的技巧 一个简单的方法,利用[数据]菜单的[分列]功能来将数字设置为文本格式.具体操作步骤为: 1.选中所有需要处理的数字单元格. 2.选择[数据]菜单[分列]功能. ...
- JS 将数字转化成为货币格式
最近由于项目的需要需要将数字format成货币格式,自己搞了半天效果不是很好,博客园有篇问题很好,再次转载记录一下 http://www.cnblogs.com/mingmingruyuedlut/a ...
- c++数字转化为字符串、字符串转换为数字
char ch[20]; int i =1; int j = 2; char *p = "34567"; 数字装换为字符串 sprintf(ch , "%d,%d&quo ...
- 整理用Java实现数字转化成字符串左边自动补零方法
Java 中给数字左边补0 (1)方法一 import java.text.NumberFormat; public class NumberFormatTest { public static vo ...
- 数字转化成字符串C语言
#include <stdio.h> void Myitoa(int,char *); int getnumberLength(int); int main(){ ]; ; Myitoa( ...
- python 中的 用chr()数值转化为字符串,字符转化为数值ord(s)函数
1.1 python字符串定义 #!/usr/bin/python # -*- coding: utf8 -*- # 定义一个字符串 s1 = 'this is long String that sp ...
- [Python]Python日期格式和字符串格式相互转换
由字符串格式转化为日期格式的函数为: datetime.datetime.strptime() 由日期格式转化为字符串格式的函数为: datetime.datetime.strftime() # en ...
- Python代码阅读(第2篇):数字转化成列表
本篇阅读的代码实现了将输入的数字转化成一个列表,输入数字中的每一位按照从左到右的顺序成为列表中的一项. 本篇阅读的代码片段来自于30-seconds-of-python. digitize def d ...
- Postgresql/Greenplum中将数字转换为字符串TO_CHAR函数前面会多出一个空格
-- 问题1..Postgresql中将数字转换为字符串前面多出一个空格. SELECT TO_CHAR(, '); -- 解决1.使用如下,参数二前面加上fm就可以去掉空格了,如下: SELECT ...
随机推荐
- WinDbg:栈帧的含义
转自:http://www.cppblog.com/weiym/archive/2012/06/07/177958.html 栈从高地址向低地址生长, __stcall和__cdecl调用约定都是函数 ...
- PL/SQL Developer import and export database method and illustrate
PL/SQL Developer import and export database method and illustrate HOW WELL DO YOU KNOW THE APPLE U ...
- CSS z-index的用法
理清 position及z-index的用法: static : 无特殊定位,对象遵循HTML定位规则absolute : 将对象从文档流中拖出,使用left,right,top,bottom等属 ...
- *Amazon problem: 234. Palindrome Linked List (reverse the linked list with n time)
Given a singly linked list, determine if it is a palindrome. Example 1: Input: 1->2 Output: false ...
- IOS 照片浏览器总结(思想步骤)
1. 界面分析========================================1> 需要读取或修改属性的控件需要设置属性// 序号标签// 图片// 图片描述// 左边按钮// ...
- BZOJ2976:[POI2002]出圈游戏(exCRT)
Description 有编号从1到n的n个小朋友在玩一种出圈的游戏,编号为i+1的小朋友站在编号为i小朋友左边.编号为1的小朋友站在编号为n的小朋友左边.首先编号为1的小朋友开始报数,接着站在左边的 ...
- HDU 1298 T9【字典树增加||查询】
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1298 T9 Time Limit: 2000/1000 MS (Java/Others) Memo ...
- PHP处理Excel
今天一个朋友问我PHP怎么导出Excel,然后我就去网上搜刮了一下资料,发现不错的第三方类PHPExcel(可以导入导出)和PHP-ExcelReader(导入).那就给大家分享一下! 一.PHP导入 ...
- Visual Studio 2010 RDLC 报表简单使用
原文:Visual Studio 2010 RDLC 报表简单使用 RDLC(Report Definition Language Client-side Processing)是Visual Stu ...
- java安装以及jdk和jre安装(简单了解)
轻松了解JDK是什么 什么是jdk? JDK是学好Java的第一步.不管是你要学习java编程,还是要搭建jsp web开发环境,或者是android开发环境都离不开它. jdk是什么呢?jdk的是j ...