---
title: "毫秒转换成时分秒 格式:HH:mm:ss Java实现"
author: "marine8888"
date: "2011-06-22T09:51:59Z"
tags: []
categories: ["移动开发"]
slug: "hh-mm-ss-java"
draft: false
lastmod: "2011-06-22T09:58:56Z"
id: 1100552
url: "https://androidstudy.iteye.com/blog/1100552"
---

```
long  ms = 300 * 1000 ;//毫秒数

SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");//初始化Formatter的转换格式。

String hms = formatter.format(ms);
```

 

可得hms 的值为  00：05：00. 即0时5分0秒。

 

将时间转换为秒：

```
        String time ="01:22:12";
        String[] my =time.split(":");
        int hour =Integer.parseInt(my[0]);
        int min =Integer.parseInt(my[1]);
        int sec =Integer.parseInt(my[2]);

        long totalSec =hour*3600+min*60+sec;

```

 其中，totalSec 的 值 即 所 需。