Calendar

    private static final SimpleDateFormat formatTimeAA = new SimpleDateFormat(" hh:mm aa MM/dd",Locale.ENGLISH);


    public Date getDate(String time,int hour) {
        String AA = " AM";
        if(hour>11){
            AA = " PM";
            if(hour>12){
                hour = hour -12;
            }
        }
        
        String pickUpDateTime = time+" "+hour+":00";

        pickUpDateTime = pickUpDateTime + AA;
        Date date = null ;
		try {
			date = formatTimeAA.parse(pickUpDateTime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        return date;
    }
  Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2013); //设定年份 // calendar.set(Calendar.MONTH, 10); //设定月份,显示的比当前多一个月 calendar.set(Calendar.DAY_OF_MONTH, 20); //设定日期 calendar.set(Calendar.HOUR_OF_DAY, 17); //设定 小时 calendar.set(Calendar.MINUTE, 30); //设定分钟 // calendar.add(Calendar.DATE, 7); //下周的 // calendar.add(Calendar.MONTH, 1); //下个月 Date date = calendar.getTime(); date.getTime(); SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); mDateFormat.format(date); Log.d("test", mDateFormat.format(date));

 

得到第二天的当前时间:

 

Date date = new Date(time);
    	int hours = date.getHours();
    	int minutes = date.getMinutes();
    	int second = date.getSeconds();
    	
    	SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, 1);
		String nextDayString = mDateFormat.format(calendar.getTime());
		String nextDayStringArray [] = nextDayString.split(" ");
		String nextDateString = nextDayStringArray[0]+" "+hours+":"+minutes + ":" + second;
		Date nextDate = null;
		try {
			nextDate = mDateFormat.parse(nextDateString);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Log.d("test", "time" + nextDate.getTime());

 long型 得到 具体时间

SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			
String preTmp = mDateFormat.format(preDate);

 

SimpleDateFormat mDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   
Date date = new Date(weekTime);

 得到时间格式:

 10:23:14 AM 11/09

 private String getTime() {
		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();
		long time = date.getTime();
		Date date2 = new Date(time);
		SimpleDateFormat mDateFormat = new SimpleDateFormat("hh:mm:ss aa MM/dd");
		mDateFormat.format(date2);
		return mDateFormat.format(date2);
	}

 

    获取手机的时间格式:

 

 ContentResolver cv = this.getContentResolver();

String  ddFormat = android.provider.Settings.System.getString(cv,
        android.provider.Settings.System.DATE_FORMAT);

        Log.d("test", "+++++++====" + ddFormat);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值