`

(转)How to convert milliseconds into human readable form?

    博客分类:
  • Java
阅读更多
x = ms / 1000
seconds = x % 60
x /= 60
minutes = x % 60
x /= 60
hours = x % 24
x /= 24
days = x

 

public static String formatMs(long millis) {
    long hours = TimeUnit.MILLISECONDS.toHours(millis);
    long mins = TimeUnit.MILLISECONDS.toMinutes(millis);
    long secs = TimeUnit.MILLISECONDS.toSeconds(millis);
    return String.format("%dh %d min, %d sec",
            hours,
            mins - TimeUnit.HOURS.toMinutes(hours),
            secs - TimeUnit.MINUTES.toSeconds(mins)
    );
}

 

转自:http://stackoverflow.com/questions/175554/how-to-convert-milliseconds-into-human-readable-form

分享到:
评论

相关推荐

    [MMS_054466]Convert milliseconds H_M_S.rar

    本资料 "[MMS_054466]Convert milliseconds H_M_S.rar" 似乎是一个关于AB PLC程序的示例,主要涉及将毫秒时间戳转换为小时、分钟和秒的逻辑。 在PLC编程中,时间处理是常见的任务,例如计时器、延时或监控事件的...

    to-milliseconds:将时间属性的对象转换为毫秒

    $ npm install @sindresorhus/to-milliseconds 用法 import toMilliseconds from '@sindresorhus/to-milliseconds' ; toMilliseconds ( { days : 15 , hours : 11 , minutes : 23 , seconds : 20 , ...

    Count Time in Milliseconds

    标题“Count Time in Milliseconds”指的是在编程中计算时间间隔的一种方法,通常用于性能测试或时间戳相关的功能。在IT领域,我们经常会遇到需要精确测量程序执行时间的情况,以优化代码效率或者理解程序运行的实时...

    毫秒与时间互相转换-精确到毫秒

    名称:MILLISECONDS2TIMESTAMP 功能:将1970-01-01 00:00:00以来的毫秒数转换为对应的timestamp时间类型,精确... SELECT TO_CHAR(MILLISECONDS2TIMESTAMP(1551804255181), 'yyyy-mm-dd hh24:mi:ss.ff3') FROM DUAL;

    Milliseconds-timer.zip_C++ Milliseconds

    这个"Milliseconds-timer.zip"压缩包提供的源代码就是一个简单的C++毫秒计时器实现。下面将详细介绍相关知识点。 1. **C++时间库**: 在C++11及更高版本中,`<chrono>`库提供了处理时间点和持续时间的能力,包括...

    humanreadable:人工可读的Python库,可将人工可读的值转换为不同的单位

    可读的人工可读的是一个Python库,用于将人工可读的值... milliseconds ))print ( "'{}' to minutes -> {}" . format ( value , hr . Time ( value ). minutes ))print ( " \n [Examples: humanreadable.BitPerSecond]

    python 实现毫秒转换为时分秒

    首先,假设我们有一个函数`milliseconds_to_hms(milliseconds)`,用于执行上述转换: ```python def milliseconds_to_hms(milliseconds): hours = milliseconds // 3600000 milliseconds %= 3600000 minutes = ...

    usec:将任何内容转换为微秒并返回

    使用 将任何东西* 转换为微秒并返回。 厌倦了在不同名称下的不同项目中实现相同的时间戳转换功能?... usec : from_msec / 1 % Convert milliseconds() to microseconds(). usec : to_msec / 1 % Convert mic

    将时间属性的对象转换为毫秒seconds22000

    `sindresorhus/to-milliseconds`库允许你直接处理包含多种时间单位(如秒、毫秒、分钟、小时等)的对象,并自动计算总毫秒数。 总结起来,JavaScript提供了多种方式来处理日期和时间,包括使用内置的`Date`对象以及...

    序列号生成器

    ### 序列号生成器实现解析 #### 一、概述 本文将深入解析一个Java实现的序列号生成器,该生成器主要用于在分布式系统中生成唯一标识符(ID)。通过分析其核心方法`nextId()`及辅助方法,我们将了解它是如何确保在...

    STG (SNMP Traffic Grapher)

    request_time - local system time (human readable string) target_uptime - target sysUpTime (hundredth of seconds) traffic traffic1 e.g.: 2001-Feb-12 15:07:28.89,24244074,5078,21215 Features ...

    TCP Ping 随意端口

    Ping2 v1.1 (14-Feb-2005 04:26:29 PM) ... --wait XX How long to wait in milliseconds between sending packets. Default is 1000 ms (1 second). Report bugs to Kurt Kincaid (sifukurt@yahoo.com)

    微软内部资料-SQL性能优化3

    It is up to the application to define what consistency means, and isolation in some form is needed to achieve consistent results. SQL Server uses locking to achieve isolation. Definition of ...

    Elasticsearch.Essentials.1784391018.pdf

    Dig into wide range of queries and find out how to use them correctly Design schema and mappings with built-in and custom analyzers Excel in data modeling concepts and query optimization Master ...

    VB编程资源大全(英文源码 控制)

    once placed onto a form, makes the form act like the Taskbar (minus the Start Menu)." -- David Newcum<END><br>2 , RemBuilderplus.zip "Rem Builder will auto load on startup to use Rem Builder;...

    SQL Sever日期转换函数集合

    为了更好地操作、显示或存储日期和时间信息,SQL Server提供了多种内置的日期转换函数,其中最为常用的就是`CONVERT`函数。`CONVERT`函数允许将日期时间值转换为不同的字符串格式,这对于数据展示和兼容性处理尤为...

    oracle中to-date详细用法示例(oracle日期格式转换).docx

    Oracle 中 TO_DATE 详细用法示例(Oracle 日期格式转换) TO_DATE 是 Oracle 中的一个日期和时间函数,用于将字符串转换为日期和时间类型。下面是 TO_DATE 的详细用法示例。 1. 日期和字符转换函数用法 TO_DATE ...

    ## @[Android studio通过jdbc连接mysql基本步骤 以及 遇到的坑“The last packet sent successfully to the server was 0 m

    @[Android studio通过jdbc连接mysql基本步骤 以及 遇到的坑“The last packet sent successfully to the server was 0 milliseconds ago”哈哈] 小白第一次发博客哈哈,记录一下这三个晚上来我的悲惨经历以及我成功...

    Billenium Effects 4.1

    16. Closing form transitions now refresh the uncovered screen to make sure it is always correct 17. TFCEmbeddedForm now publishes ParentColor and ParentShowHint properties 18. Closing form effects ...

    C#实现毫秒转换成时分秒的方法

    public static string FormatMillisecondsToTimeStr(long milliseconds) { // 初始化小时、分钟和秒的变量 int hours = 0; int minutes = 0; int seconds = 0; // 首先将毫秒转换为秒 seconds = (int)...

Global site tag (gtag.js) - Google Analytics