时间转换工具类
来源:互联网 发布:在线相片制作软件 编辑:程序博客网 时间:2024/04/28 09:06
日期转获取字符串
/** * 日期转获取字符串 * * @param date日期 * @param format格式 ("yyyy-MM-dd hh:mm:ss") * hh:表示12时制 * HH 表示24时制 * @return */ public static String getDate(Date date, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); }
系统当前时间
/** * 获取系统当前日期(格式2012-12-28 13:58:00) * * @return */ public static String getSysDate() { return getDate(new Date(System.currentTimeMillis()), "yyyy-MM-dd HH:mm:ss"); }
获取小时和分钟
/** * 获取小时 * @return */ public static int getHourOfDay() { return Calendar.getInstance().get(Calendar.HOUR_OF_DAY); } /** * 获取分钟 * @return */ public static int getMinute() { return Calendar.getInstance().get(Calendar.MINUTE); } /** * 获取小时 * * @return */ public static int getHourOfDay(long time) { Date date = new Date(time); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.HOUR_OF_DAY); }
获取一天中时分秒
/** * 取出时分秒,并转化为long类型 * 2017-12-13 15:47:43 -> 15:47:43 -> 56863000 */ public static long filterHms(long curTime) { String str = getDate(curTime, "HH:mm:ss"); String time[] = str.split(":"); int hour = Integer.parseInt(time[0]); int minute = Integer.parseInt(time[1]); int second = Integer.parseInt(time[2]); return hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000; }
DateTimeUtil工具栏
package com.sufadi.nightmode.util;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;public class DateTimeUtil { /** * 获取系统当前日期(格式2012-12-28 13:58:00) * * @return */ public static String getSysDate() { return getDate(new Date(System.currentTimeMillis()), "yyyy-MM-dd HH:mm:ss"); } public static String getSysDate(long time) { return getDate(time, "yyyy-MM-dd HH:mm:ss"); } /** * 获取系统当前日期(格式2012-12-28) * * @return */ public static String getSysDateYMD() { return getDate(new Date(System.currentTimeMillis()), "yyyy-MM-dd"); } /** * 获取系统当前时间(格式13:58:00) * * @return */ public static String getSysTimeHMS() { return getDate(new Date(System.currentTimeMillis()), "HH:mm:ss"); } /** * 日期转获取字符串 * * @param date日期 * @param format格式 ("yyyy-MM-dd hh:mm:ss") * hh:表示12时制 * HH 表示24时制 * @return */ public static String getDate(Date date, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(date); } public static String getDate(long time, String format) { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.format(new Date(time)); } /** * 获取天数 * @return */ public static int getDayOfYear() { return Calendar.getInstance().get(Calendar.DAY_OF_YEAR); } /** * 获取小时 * @return */ public static int getHourOfDay() { return Calendar.getInstance().get(Calendar.HOUR_OF_DAY); } /** * 获取小时 * * @return */ public static int getHourOfDay(long time) { Date date = new Date(time); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.HOUR_OF_DAY); } /** * 获取分钟 * @return */ public static int getMinute() { return Calendar.getInstance().get(Calendar.MINUTE); } /** * 获取分钟 * * @return */ public static int getMinute(long time) { Date date = new Date(time); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return calendar.get(Calendar.MINUTE); } /** * 取出时分秒,并转化为long类型 * 2017-12-13 15:47:43 -> 15:47:43 -> 56863000 */ public static long filterHms(long curTime) { String str = getDate(curTime, "HH:mm:ss"); String time[] = str.split(":"); int hour = Integer.parseInt(time[0]); int minute = Integer.parseInt(time[1]); int second = Integer.parseInt(time[2]); return hour * 60 * 60 * 1000 + minute * 60 * 1000 + second * 1000; }}
阅读全文
0 0
- 时间转换工具类
- 时间转换工具类
- 时间转换工具类
- Android 时间转换工具类
- Android工具类(时间转换)
- 时间转换处理工具类
- android 时间转换工具类
- DateUtil时间转换工具类
- 3.时间转换工具类
- Java获取时间 时间计算 转换时间工具类
- 通用工具-Time时间转换类
- DateUtil工具类时间戳类型转换
- java日期时间转换工具类
- Android 日期时间等转换工具类
- 新浪微博时间转换工具类
- Android开发 时间戳转换工具类
- 工具类--TimeUtil 时间格式化与转换
- Date&String时间转换工具类
- Extjs 中Tabpanel使用以及tab切换事件
- Django的login和authenticate模块的使用
- Git flow的使用
- 简单的网站服务器
- JAVA之经典算法二
- 时间转换工具类
- Luogu-3391 (splay模板)
- dpi 、 dip 、分辨率、屏幕尺寸、px、density 关系以及换算
- CentOS折腾codeblocks
- c++ 项目文件 .sln和 .vcxproj,为解决方案创造文件
- 树莓派扩展板(万用板)
- Map(1)--Map集合的常用功能
- Codeforces Round #448 (Div. 2) D. String Mark
- dpkg: warning: files list file for package `*****' missing, assuming package has no files currently