猿问

131460562376400000这个是啥子时间戳哦,请问各位!

如题,我该如何把这个131460562376400000转换为java的yyyy-mm-dd HH:mm:ss.SSS呢,试过了以下方法都不得行!

/**
     * 将C#的ticks值转换成Java的yyyy-mm-dd HH:mm:ss.SSS
     *
     * @param ticks
     * @return
     */
    public static String fromDnetTicks2JdateString(long ticks) {
        TimeZone timeZone = TimeZone.getDefault();
        long TICKS_PER_MILLISECOND = 10000;
        long TICKS_AT_EPOCH = 621355968000000000L;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        Calendar calendar = Calendar.getInstance(timeZone);
        calendar.setTimeInMillis((ticks - TICKS_AT_EPOCH) / TICKS_PER_MILLISECOND);
        calendar.setTimeInMillis(calendar.getTimeInMillis() - calendar.getTimeZone().getRawOffset());
        return sdf.format(calendar.getTime());
    }
    

  

拉风的咖菲猫
浏览 433回答 1
1回答
随时随地看视频慕课网APP

相关分类

Java
我要回答