/**
 * 
 */
package com.hd.admin.wxmeet.utils;
/**
 * @author jymcpp
 *
 */
import java.text.DateFormat;  
import java.text.ParseException;  
import java.text.SimpleDateFormat;  
import java.util.Date;  
  
public class wxLongutils {  
    public static void main(String[] args){  
        String createTime = "1483084803";  
        String formatTime = formatTime(createTime);  
        System.out.println(formatTime);  
        String year = formatTime.substring(6, 10);  
        String month = formatTime.substring(0, 2);  
        String day = formatTime.substring(3, 5);  
        String hour = formatTime.substring(11, 13);  
        String minute = formatTime.substring(14, 16);  
        String second = formatTime.substring(17, 19);  
        System.out.println(year);  
        System.out.println(Long.parseLong(month));  
        System.out.println(day);  
        System.out.println(hour);  
        System.out.println(minute);  
        System.out.println(second);  
          
        String sDt = "08/07/2014 10:14:36";  
        System.out.println(formatToLongTime(sDt));  
    }  
    /** 
     * 将微信消息中的CreateTime转换成标准格式的时间(MM/dd/yyyy HH:mm:ss) 
     *  
     * @param createTime 消息创建时间 
     * @return 
     */  
    public static String formatTime(String createTime) {  
        // 将微信传入的CreateTime转换成long类型,再乘以1000  
        long msgCreateTime = Long.parseLong(createTime) * 1000L;  
        DateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
        return format.format(new Date(msgCreateTime));  
    }  
    /** 
     * 将标准格式的时间(MM/dd/yyyy HH:mm:ss)转换为微信服务器的long型 
     * @param formatTime 
     * @return 
     * @throws ParseException  
     */  
    public static long formatToLongTime(String formatTime){  
        SimpleDateFormat sdf= new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");  
        Date dt2;  
        try {  
            dt2 = sdf.parse(formatTime);  
            return dt2.getTime() / 1000;  
        } catch (ParseException e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }  
        //转换失败返回值  
        return -1;  
    }  
}  

最新文章

  1. 为更好地设计数据库,重新整理sql server数据类型
  2. iOS学习之iOS沙盒(sandbox)机制和文件操作(二)
  3. C++指针之防不胜防
  4. pb中读取大文本数据
  5. Error when running Swift3 in REPL
  6. 取消jQuery validate验证
  7. ios专题 -block用法
  8. js 实现tab选项卡
  9. CI的扩展机制
  10. 用C语言写解释器(一)——我们的目标
  11. 文《左右c++与java中国的垃圾问题的分析与解决》一bug分析
  12. JavaScript变量存储浅析
  13. Git (gnome-ssh-askpass:3871): Gtk-WARNING **: cannot open display:
  14. Chapter 2 User Authentication, Authorization, and Security(5):使用固定服务器角色
  15. CodeForces 958F3 Lightsabers (hard) 启发式合并/分治 多项式 FFT
  16. 挑选队友 (生成函数 + FFT + 分治)
  17. emqtt在centos6下的安装
  18. 黑客炼金术士 Seeker:可以攻破 4G 摸到你短信,还要为朝阳群众提供谍战工具
  19. laravel5实现第三方登录(微信)
  20. easyUI拖动购物车案例

热门文章

  1. [LeetCode] Valid Word Abbreviation 验证单词缩写
  2. spring定时器,定时器一次执行两次的问题
  3. Shell命令_smem
  4. 手机GUI自动化测试工具选择
  5. python_java_selenium_ jenkins持续集成Firfox_chrome浏览器不显示的解决方法?
  6. bzoj 1061 志愿者招募 有上下界费用流做法
  7. POJ 1149 PIGS
  8. 北京培训记day2
  9. centeros:生产环境搭建
  10. 懒加载(getter\setter理解)