栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Windows

时间戳如何转换为日期格式?MySQL、C#、JS时间戳转换方法

Windows 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

时间戳如何转换为日期格式?MySQL、C#、JS时间戳转换方法

  时间戳如何转换为日期格式?当初把日期格式转换为时间戳是为了更好的记录数据,现在如果想要看看当初时间戳被转换的时间,可以按照以下方法来实现,详情请阅读下文MySQL、C#、JS时间戳转换方法。

  MySQL、C#、JS时间戳转换方法:

  一、MySQL戳转换方法:

  1、原理:

  时间戳的原理是把时间格式转为十进制格式,这样就方便时间的计算,如:1377216000000 转化后是 2013年08月23日 。

  2、步骤:

  (1) 创建 DateUtilsl类。

  (2) 输入代码:

  1. 01importjava.text.ParseException;
  2. 02importjava.text.SimpleDateFormat;
  3. 03importjava.util.Date;  
  4. 04
  5. 07public class DateUtils {  
  6. 08privateSimpleDateFormat sf = null;
  7. 09
  8. 10public static String getCurrentDate() {
  9. 11Date d = newDate();
  10. 12sf = newSimpleDateFormat("yyyy年MM月dd日");
  11. 13returnsf.format(d);
  12. 14}  
  13. 15
  14. 16public static String getDateToString(long time) {
  15. 17Date d = newDate(time);
  16. 18sf = newSimpleDateFormat("yyyy年MM月dd日");
  17. 19returnsf.format(d);
  18. 20}  
  19. 21
  20. 22public static long getStringToDate(String time) {
  21. 23sdf = newSimpleDateFormat("yyyy年MM月dd日");
  22. 24Date date = newDate();
  23. 25try{
  24. 26date = sdf.parse(time);
  25. 27} catch(ParseException e) {
  26. 28// TODO Auto-generated catch block
  27. 29e.printStackTrace();
  28. 30}
  29. 31returndate.getTime();
  30. 32}
复制代码 importjava.text.ParseException; importjava.text.SimpleDateFormat; importjava.util.Date;   public class DateUtils {   privateSimpleDateFormat sf = null; public static String getCurrentDate() { Date d = newDate(); sf = newSimpleDateFormat("yyyy年MM月dd日"); returnsf.format(d); }   public static String getDateToString(long time) { Date d = newDate(time); sf = newSimpleDateFormat("yyyy年MM月dd日"); returnsf.format(d); }   public static long getStringToDate(String time) { sdf = newSimpleDateFormat("yyyy年MM月dd日"); Date date = newDate(); try{ date = sdf.parse(time); } catch(ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } returndate.getTime(); }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/559833.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号