안 드 로 이 드 가 초 단위 로 전환 하 는 방법

시간 을 바 꾸 는 과정 에서 보통 초 를 시 분 초의 작은 기능 으로 바 꾸 는데 어떻게 해 야 할 수 있 습 니까?사실은 간단 합 니 다.이것 은 그 때 분 초 간 의 상호 전환 과 관련 됩 니 다.
구체 적 인 코드 는 다음 과 같다.

import android.content.Context;
public class ToolsUtil {
 private static ToolsUtil toolsUtil;
 private Context mContext;
 private ToolsUtil(Context context) {
  mContext = context.getApplicationContext();
 }
 public static ToolsUtil getInstance(Context context) {
  if (toolsUtil == null) {
   toolsUtil = new ToolsUtil(context);
  }
  return toolsUtil;
 }
 public String timeConversion(int time) {
  int hour = 0;
  int minutes = 0;
  int sencond = 0;
  int temp = time % 3600;
  if (time > 3600) {
   hour = time / 3600;
   if (temp != 0) {
    if (temp > 60) {
     minutes = temp / 60;
     if (temp % 60 != 0) {
      sencond = temp % 60;
     }
    } else {
     sencond = temp;
    }
   }
  } else {
   minutes = time / 60;
   if (time % 60 != 0) {
    sencond = time % 60;
   }
  }
  return (hour<10?("0"+hour):hour) + ":" + (minutes<10?("0"+minutes):minutes) + ":" + (sencond<10?("0"+sencond):sencond);
 }
}
이렇게 해서 시간 을 00:00:00 의 시간 형식 으로 바 꿨 습 니 다.
ps:다음은 안 드 로 이 드 가 초 를 통 해 시간 분 초 로 환산 하 는 것 을 보 겠 습 니 다.
초 를 시 분 초 로 환산 하 다

public static String cal(int second) {
    int h = 0;
    int d = 0;
    int s = 0;
    int temp = second % 3600;
    if (second > 3600) {
      h = second / 3600;
      if (temp != 0) {
        if (temp > 60) {
          d = temp / 60;
          if (temp % 60 != 0) {
            s = temp % 60;
          }
        } else {
          s = temp;
        }
      }
    } else {
      d = second / 60;
      if (second % 60 != 0) {
        s = second % 60;
      }
    }
    return h + " " + d + " " + s + " ";
  }
초 를 통 해 몇 시간 몇 분 몇 초 를 나 눌 수 있 습 니까?

public class TimeUtils {
  public static String getHours(long second) {//        
    long h = 00;
    if (second > 3600) {
      h = second / 3600;
    }
    return h+"";
  }

  public static String getMins(long second) {//       
    long d = 00;
    long temp = second % 3600;
    if (second > 3600) {
      if (temp != 0) {
        if (temp > 60) {
          d = temp / 60;
        }
      }
    } else {
      d = second / 60;
    }
    return d + "";
  }
  public static String getSeconds(long second) {//       
    long s = 0;
    long temp = second % 3600;
    if (second > 3600) {
      if (temp != 0) {
        if (temp > 60) {
          if (temp % 60 != 0) {
            s = temp % 60;
          }
        } else {
          s = temp;
        }
      }
    } else {
      if (second % 60 != 0) {
        s = second % 60;
      }
    }
    return s + "";
  }

}
총결산
안 드 로 이 드 가 초 단위 로 전환 하 는 방법 에 관 한 이 글 은 여기까지 소개 되 었 습 니 다.더 많은 관련 안 드 로 이 드 초 단위 로 전환 하 는 내용 은 우리 의 이전 글 을 검색 하거나 아래 의 관련 글 을 계속 찾 아 보 세 요.앞으로 많은 응원 부탁드립니다!

좋은 웹페이지 즐겨찾기