parent
4d740446a1
commit
b78bd398ea
@ -1,82 +0,0 @@ |
||||
package com.frank.ffmpeg.util; |
||||
|
||||
import java.text.ParseException; |
||||
import java.text.SimpleDateFormat; |
||||
import java.util.Date; |
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* the tool of time transforming |
||||
* Created by frank on 2018/11/12. |
||||
*/ |
||||
|
||||
public class TimeUtil { |
||||
|
||||
private static final String YMDHMS = "yyyy-MM-dd HH:mm:ss"; |
||||
|
||||
/** |
||||
* convert timestramp into String |
||||
* |
||||
* @param time time |
||||
* @return yyyy/MM/dd HH:mm:ss |
||||
*/ |
||||
public static String getDetailTime(long time) { |
||||
SimpleDateFormat format = new SimpleDateFormat(YMDHMS, Locale.getDefault()); |
||||
Date date = new Date(time); |
||||
return format.format(date); |
||||
} |
||||
|
||||
/** |
||||
* convert normal time into timestamp |
||||
* |
||||
* @param time time |
||||
* @return timestamp |
||||
*/ |
||||
public static long getLongTime(String time, Locale locale) { |
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(YMDHMS, locale); |
||||
try { |
||||
Date dt = simpleDateFormat.parse(time); |
||||
return dt.getTime(); |
||||
} catch (ParseException e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
private static String addZero(int time) { |
||||
if (time >= 0 && time < 10) { |
||||
return "0" + time; |
||||
} else if (time >= 10) { |
||||
return "" + time; |
||||
} else { |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* convert timestamp into video time |
||||
* |
||||
* @param time time |
||||
* @return video time |
||||
*/ |
||||
public static String getVideoTime(long time) { |
||||
if (time <= 0) |
||||
return null; |
||||
time = time / 1000; |
||||
int second, minute = 0, hour = 0; |
||||
second = (int) time % 60; |
||||
time = time / 60; |
||||
if (time > 0) { |
||||
minute = (int) time % 60; |
||||
hour = (int) time / 60; |
||||
} |
||||
if (hour > 0) { |
||||
return addZero(hour) + ":" + addZero(minute) + ":" + addZero(second); |
||||
} else if (minute > 0) { |
||||
return addZero(minute) + ":" + addZero(second); |
||||
} else { |
||||
return "00:" + addZero(second); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,82 @@ |
||||
package com.frank.ffmpeg.util |
||||
|
||||
import java.text.ParseException |
||||
import java.text.SimpleDateFormat |
||||
import java.util.Date |
||||
import java.util.Locale |
||||
|
||||
/** |
||||
* the tool of time transforming |
||||
* Created by frank on 2018/11/12. |
||||
*/ |
||||
|
||||
object TimeUtil { |
||||
|
||||
private const val YMDHMS = "yyyy-MM-dd HH:mm:ss" |
||||
|
||||
/** |
||||
* convert timestramp into String |
||||
* |
||||
* @param time time |
||||
* @return yyyy/MM/dd HH:mm:ss |
||||
*/ |
||||
fun getDetailTime(time: Long): String { |
||||
val format = SimpleDateFormat(YMDHMS, Locale.getDefault()) |
||||
val date = Date(time) |
||||
return format.format(date) |
||||
} |
||||
|
||||
/** |
||||
* convert normal time into timestamp |
||||
* |
||||
* @param time time |
||||
* @return timestamp |
||||
*/ |
||||
fun getLongTime(time: String, locale: Locale): Long { |
||||
val simpleDateFormat = SimpleDateFormat(YMDHMS, locale) |
||||
try { |
||||
val dt = simpleDateFormat.parse(time) |
||||
return dt.time |
||||
} catch (e: ParseException) { |
||||
e.printStackTrace() |
||||
} |
||||
|
||||
return 0 |
||||
} |
||||
|
||||
private fun addZero(time: Int): String { |
||||
return when { |
||||
time in 0..9 -> "0$time" |
||||
time >= 10 -> "" + time |
||||
else -> "" |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* convert timestamp into video time |
||||
* |
||||
* @param t time |
||||
* @return video time |
||||
*/ |
||||
fun getVideoTime(t: Long): String? { |
||||
var time = t |
||||
if (time <= 0) |
||||
return null |
||||
time /= 1000 |
||||
val second: Int |
||||
var minute = 0 |
||||
var hour = 0 |
||||
second = time.toInt() % 60 |
||||
time /= 60 |
||||
if (time > 0) { |
||||
minute = time.toInt() % 60 |
||||
hour = time.toInt() / 60 |
||||
} |
||||
return when { |
||||
hour > 0 -> addZero(hour) + ":" + addZero(minute) + ":" + addZero(second) |
||||
minute > 0 -> addZero(minute) + ":" + addZero(second) |
||||
else -> "00:" + addZero(second) |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue