Excel中日期与数字的转换代码_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > Excel中日期与数字的转换代码

Excel中日期与数字的转换代码

 2014/5/31 10:02:34  jsx112  程序员俱乐部  我要评论(0)
  • 摘要:publicstaticvoidmain(String[]args){intdays=41829;doubleditNumber=0.4330324074;Datedate=getDate(days);DatedateTime=getTime(date,ditNumber);SimpleDateFormatsdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");System.out.println(sdf.format(dateTime));
  • 标签:excel 代码
class="java" name="code">    public static void main(String[] args) {
        int days = 41829;
        double ditNumber = 0.4330324074;
        Date date = getDate(days);
        Date dateTime = getTime(date, ditNumber);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(dateTime));
    }
    
    public static Date getDate(int days) {
        Calendar c = Calendar.getInstance();
        c.set(1900, 0, 1);
        c.add(Calendar.DATE, days - 2);
        return c.getTime();
    }
    
    public static Date getTime(Date date, double ditNumber) {
        Calendar c = Calendar.getInstance();
        int mills = (int) (Math.round(ditNumber * 24 * 3600));
        int hour = mills / 3600;
        int minute = (mills - hour * 3600) / 60;
        int second = mills - hour * 3600 - minute * 60;
        c.setTime(date);
        c.set(Calendar.HOUR_OF_DAY, hour);
        c.set(Calendar.MINUTE, minute);
        c.set(Calendar.SECOND, second);
        return c.getTime();
    }

?

发表评论
用户名: 匿名