Java Utililty Methods Milliseconds Parse

List of utility methods to do Milliseconds Parse

  1. HOME
  2. Java
  3. M
  4. Milliseconds Parse

Description

The list of methods to do Milliseconds Parse are organized into topic(s).

Method

String changeMillSecond2Date(long millSeconds)
change Mill Second Date
Date temp = new Date(millSeconds);
return formatDateMinutes(temp);
long getTimeAsMillis(String value)
A time can be passed in as a long in millis, or with a unit on it, like '60s'.
if (value.indexOf("ms") != -1) {
 return Long.parseLong(value.substring(0, value.indexOf("ms")));
} else if (value.indexOf("s") != -1) {
 return 1000 * Long.parseLong(value.substring(0, value.indexOf("s")));
} else if (value.indexOf("m") != -1) {
 return 1000 * 60 * Long.parseLong(value.substring(0, value.indexOf("m")));
} else if (value.indexOf("h") != -1) {
 return 1000 * 60 * 60 * Long.parseLong(value.substring(0, value.indexOf("h")));
...
String getTimeFromMilliseconds(long ms)
get Time From Milliseconds
int time = (int) ms / 1000;
int seconds = time % 60;
int mintues = (time % 3600) / 60;
int hours = time / 3600;
String format = String.format("%%0%dd", 2);
String secondsString = String.format(format, seconds);
String mintuesString = String.format(format, mintues);
String hoursString = String.format(format, hours);
...
long getTimeInMilliseconds(String timeString)
Convert a formatted time string to a count in milliseconds.
long hours = 0;
long minutes = 0;
long seconds = 0;
long milliseconds = 0;
int firstColonIndex = timeString.indexOf(":");
int lastColonIndex = timeString.lastIndexOf(":");
int periodIndex = timeString.lastIndexOf(".");
if (periodIndex != -1) {
...
long getTimeMillis(long FileTimestamp)
get Time Millis
FileTimestamp -= FT_UT_OFFSET;
FileTimestamp /= 10000;
FileTimestamp -= 14 * 60 * 60 * 1000;
return FileTimestamp;
long getTimeMillis(String time)
Transforms the string into a millisecond timestamp
- Days in d, day or days
- Hours in h, hour or hours
- Minutes in m, minute or minutes
- Seconds in s, second or seconds

returns -1 if the time cannot be transformed
long date = 0;
String[] splits = time.split(" ");
try {
 for (String s : splits) {
 if (s.length() > 1 && (s.endsWith("d") || s.endsWith("day") || s.endsWith("days"))) {
 date += Integer.parseInt(s.substring(0, s.length() - 1)) * 24 * 60 * 60 * 1000;
 } else if (s.length() > 1 && (s.endsWith("h") || s.endsWith("hour") || s.endsWith("hours"))) {
 date += Integer.parseInt(s.substring(0, s.length() - 1)) * 60 * 60 * 1000;
...
Date parseDate(long millisec)
parse Date
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(millisec);
Date date = calendar.getTime();
return date;
long parseGMTInMillis(String time)
parse GMT In Millis
synchronized (GMT_FORMAT_MILLIS) {
 return GMT_FORMAT_MILLIS.parse(time).getTime() * 1000000L;
long parseMillis(String s)
Parses a formatted String and returns the value in milliseconds.
if (s == null) {
 return 0;
long millis = 0;
int i = 0;
int length = s.length();
while (i < length) {
 long delta = 0;
...
int parseMillisecond(String date)
parse Millisecond
String[] tt = date.split("[^\\d]+");
int ms = 0;
for (int i = 0; i < tt.length - 1; i++) {
 ms = ms * 60 + getInt(tt[i]);
ms = ms * 1000 + getInt(tt[tt.length - 1]);
return ms;


AltStyle によって変換されたページ (->オリジナル) /