• java时区问题设置,new Date()和系统时间相差8个小时


    出现这种问题有可能是服务时间没有修改。

    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;

    import java.util.Date;

    import java.util.TimeZone;

    public class GetNowDate {


    //获取系统当前时间,字符串类型
    public static String getStrDate(){
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //设置为东八区
    sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    Date newDate = new Date();
    String dateStr = sdf.format(newDate);
    return dateStr;
    }

    //获取系统当前时间Date类型,需要将字符串类型转成时间
    public static Date getDaDate(){
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    //设置为东八区
    sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
    Date date = new Date();
    String dateStr = sdf.format(date);

    //将字符串转成时间
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date newDate=null;
    try {
    newDate = df.parse(dateStr);
    } catch (ParseException e) {
    e.printStackTrace();
    }
    return newDate;
    }

    }

  • 相关阅读:
    ASP.Net验证码类
    net进行Socket通信
    web browser 小结
    WebService远程调试
    javascript 资料(一)
    释放非托管资源 IDisposable模式的实现、使用
    asp.net2.0 WebForm_DoPostBackWithOptions
    使用jquery.json把js对象转换成json
    多选列表双击选中
    JQuery对Select的操作
  • 原文地址:https://www.cnblogs.com/guangxiang/p/11050890.html
Copyright © 2020-2023  润新知