目前分類:未分類文章 (2)

瀏覽方式: 標題列表 簡短摘要

API載點: https://jar-download.com/artifacts/joda-time/joda-time/2.9.4/source-code

import org.joda.time.Interval;
import org.joda.time.Period;

public class TimeTool {

        public static String longToTime(long time) {
                int tns, thh, tmm, tss;
                tns = (int) time / 1000;
                thh = tns / 3600;
                tmm = (tns % 3600) / 60;
                tss = (tns % 60);

                String format_thh = String.format("%2d", thh).replace(" ", "0");
                String format_tmm = String.format("%2d", tmm).replace(" ", "0");
                String format_tss = String.format("%2d", tss).replace(" ", "0");
                
                return format_thh + ":" + format_tmm + ":" + format_tss;
        }

        public static String longToDate(long time) {
                int tns, tYYYY = 0, tMM = 0, tDD, thh;
                tns = (int) time / 1000;
                thh = tns / 3600;
                tDD = thh/24;
                
                
                String format_tYYYY = String.format("%4d", tYYYY).replace(" ", "0");
                String format_tMM = String.format("%2d", tMM).replace(" ", "0");
                String format_tDD = String.format("%2d", tDD).replace(" ", "0");
                
                return format_tYYYY + "-" + format_tMM + "-" + format_tDD;
        }

        public static String longToDateTime(long time) {

                return null;
        }

        public static String dateToLong() {

                return null;
        }

        public static String timeToLong() {

                return null;
        }

        public static String datetimeToLong() {

                return null;
        }

        public static String datetimeToTime() {

                return null;
        }

        public static String datetimeToDate() {

                return null;
        }

        public static String countDate(Date startTime, Date endTime) {
                Interval interval = new Interval(startTime.getTime(), endTime.getTime());
                Period period = interval.toPeriod();

                String format_thh = String.format("%2d", period.getHours()).replace(" ", "0");
                String format_tmm = String.format("%2d", period.getMinutes()).replace(" ", "0");
                String format_tss = String.format("%2d", period.getSeconds()).replace(" ", "0");

                return format_thh + ":" + format_tmm + ":" + format_tss;
        }
        
        public static String getSystemTime() {
                SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss");

                return sdf.format(new Date());
        }
        
        public static String getSystemDateTime() {
                SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM-dd hh:mm:ss");
                
                return sdf.format(new Date());
        }
        
        public static void main(String[] args) {
                System.out.println(longToTime(1000002551));
                System.out.println(longToDate(1000110110));
                System.out.println(longToDateTime(0101010110));
                System.out.println(dateToLong());
                System.out.println(timeToLong());
                System.out.println(datetimeToLong());
                System.out.println(datetimeToTime());
                System.out.println(datetimeToDate());
                System.out.println(getSystemDateTime());
        }
}


Kingkazma 發表在 痞客邦 留言(0) 人氣()

 

ctrl+shift+O-->將package自動引用及移除

文章標籤

Kingkazma 發表在 痞客邦 留言(0) 人氣()