JAVA 的data类型 long类型 生成星期几汇总
发布日期:2021-11-12 07:57:10 浏览次数:25 分类:技术文章

本文共 1611 字,大约阅读时间需要 5 分钟。

原文网址:http://www.cnblogs.com/qgzhan/archive/2013/05/26/3100319.html

**

* 时间的操作类

* */
public class TimeUtil {

/**
* 返回系统时间

* @param void
* @return 系统时间 long

* */
public static long CurrentTime() {

return System.currentTimeMillis();

}

/**
* 返回年-月-日 hh:ff:ss

* @param time
* long系统时间的long类型
* @return String yyyy-MM-dd HH:mm:ss类型的时间类型
* */
public static String getFormatTime(long time) {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date date = new Date(time);

String formatTime = format.format(date);

return formatTime;

}

/**
* 星期几

* @param data
* Date 日期
* @return 星期一到星期日

* */
public static String getWeekOfDate(Date date) {


String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;

return weekDays[w];
}

/**
* 星期几

* @param time
* long 系统时间的long类型
* @return 星期一到星期日

* */
public static String getWeekOfDate(long time) {

Date date = new Date(time);
String[] weekDays = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
Calendar cal = Calendar.getInstance();
cal.setTime(date);
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
w = 0;

return weekDays[w];
}

/**
* 返回年-月-日 hh:ff:ss 星期几

* @param time
* long系统时间
* @return String 例如2013-05-26 19:39:26 星期日

* */

public static String getDateAndWeek(long time) {

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date date = new Date(time);

String dateString = format.format(date);

String dayString = getWeekOfDate(date);

return dateString + " " + dayString;

}

}

转载地址:https://blog.csdn.net/happy_love1990/article/details/69488112 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android 重写EditText回车事件
下一篇:Android监听home键的方法

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年03月06日 17时14分20秒