系统时间、星期、年月日

获取系统的当前时间

long time = System.currentTimeMillis();

以不同的格式显示
(1) 2015-11-11 11:08:34
(2) 2015/01/06 06-36-23
……

SimpleDateFormat sdff = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  

Date date = new Date(System.currentTimeMillis());  

String str_date = sdf.format(date);  

通过Calendar类获取年、月、日、星期(int类型1~7)


Calendar calendar = Calendar.getInstance();  

int year = calendar.get(Calendar.YEAR);  

//从0开始,一月得到的month=0 
int month = calendar.get(Calendar.MONTH);

int day = calendar.get(Calendar.DAY_OF_MONTH);  

int weekk = calendar.get(Calendar.DAY_OF_WEEK);  

获取当前是星期几

Date date = new Date(System.currentTimeMillis());  

Calendar calendar = Calendar.getInstance();  

calendar.setTime(date);  

String week = "周";  

if(calendar.get(Calendar.DAY_OF_WEEK) == 1)  
{  
    week +="日";  
}else if(calendar.get(Calendar.DAY_OF_WEEK) == 2)  
{  
    week +="一";  
}else if(calendar.get(Calendar.DAY_OF_WEEK) == 3)  
{  
    week +="二";  
}else if(calendar.get(Calendar.DAY_OF_WEEK) == 4)  
{  
    week +="三";  
}else if(calendar.get(Calendar.DAY_OF_WEEK) == 5)  
{  
    week +="四";  
}else if(calendar.get(Calendar.DAY_OF_WEEK) == 6)  
{  
    week +="五";  
}else if(calendar.get(Calendar.DAY_OF_WEEK) == 7)  
{  
    week +="六";  
}   

//最终获取的格式是:周六
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值