当前位置: 首页>>代码示例>>Java>>正文


Java DateFormat.parse方法代码示例

本文整理汇总了Java中java.text.DateFormat.parse方法的典型用法代码示例。如果您正苦于以下问题:Java DateFormat.parse方法的具体用法?Java DateFormat.parse怎么用?Java DateFormat.parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.DateFormat的用法示例。


在下文中一共展示了DateFormat.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert2StandardFormat

import java.text.DateFormat; //导入方法依赖的package包/类
/**
   * 转换日期格式
   * @param 时间字符串  将yyyy-MM-dd HH:mm:ss 转成 yyyyMMddHHmmss
   */
  public static String convert2StandardFormat(String dateTimeStr) {
  	
  	DateFormat dbDateFormat = dbDateFormatThreadLocal.get();
  	DateFormat dateFormat = dateFormatThreadLocal.get();
  	Date date;
  	String formatedDateStr = null;
try {
	date = dbDateFormat.parse(dateTimeStr);
	formatedDateStr = dateFormat.format(date);
} catch (ParseException e) {
	e.printStackTrace();
};
  	
  	return formatedDateStr;
  }
 
开发者ID:smxc,项目名称:garlicts,代码行数:20,代码来源:DateUtil.java

示例2: compare

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * 比较两个日期的大小。<br>
 * 若date1 > date2 则返回 1<br>
 * 若date1 = date2 则返回 0<br>
 * 若date1 < date2 则返回-1
 * @autor:chenssy
 * @date:2014年9月9日
 *
 * @param date1  
 * @param date2
 * @param format  待转换的格式
 * @return 比较结果
 */
public static int compare(String date1, String date2,String format) {
    DateFormat df = DateFormatUtils.getFormat(format);
    try {
        Date dt1 = df.parse(date1);
        Date dt2 = df.parse(date2);
        if (dt1.getTime() > dt2.getTime()) {
            return 1;
        } else if (dt1.getTime() < dt2.getTime()) {
            return -1;
        } else {
            return 0;
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return 0;
}
 
开发者ID:onsoul,项目名称:os,代码行数:31,代码来源:DateUtils.java

示例3: compareDate

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * 日期大小比较 date1大于date2返回1; date1小于date2返回-1 date1等于date2返回0
 * 
 * @param date1
 * @param date2
 * @return
 */
@SuppressLint("SimpleDateFormat")
public static int compareDate(String date1, String date2) {
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	try {
		Date dt1 = df.parse(date1);
		Date dt2 = df.parse(date2);
		if (dt1.getTime() > dt2.getTime()) {
			return 1;
		} else if (dt1.getTime() < dt2.getTime()) {
			return -1;
		} else {
			return 0;
		}
	} catch (Exception exception) {
		exception.printStackTrace();
	}
	return 0;
}
 
开发者ID:caichengan,项目名称:ShoppingCartActivity,代码行数:26,代码来源:StringUtil.java

示例4: compare_date

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * 两个日期比较
 * @param DATE1
 * @param DATE2
 * @return
 */
public static int compare_date(String DATE1, String DATE2) {
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
    try {
        Date dt1 = df.parse(DATE1);
        Date dt2 = df.parse(DATE2);
        if (dt1.getTime() - dt2.getTime()>0) {//date1>date2
            return 1;
        } else {
            return -1;
        }
    } catch (Exception exception) {
        exception.printStackTrace();
    }
    return 0;
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:22,代码来源:TimeUtil.java

示例5: test_setAndGetTimestamp

import java.text.DateFormat; //导入方法依赖的package包/类
@Test
public void test_setAndGetTimestamp() throws ParseException {


    User user = new User();
    Group group = new Group("Group 1");
    Message message = new Message("Body", user, group);

    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Date date = dateFormat.parse("01/01/2017");
    long time = date.getTime();
    Timestamp timestamp = new Timestamp(time);
    message.setTimestamp(timestamp);

    assertEquals("timestamp not equal", message.getTimestamp(),date);
}
 
开发者ID:tosinoni,项目名称:SECP,代码行数:17,代码来源:MessageTest.java

示例6: date

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * Reads a "date" argument from the request.
 * TODO handle timezones properly
 */
public Date date(ImapRequestLineReader request) throws ProtocolException {
    char next = request.nextWordChar();
    String dateString;
    if (next == '"') {
        dateString = consumeQuoted(request);
    } else {
        dateString = atom(request);
    }

    DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
    try {
        return dateFormat.parse(dateString);
    } catch (ParseException e) {
        throw new ProtocolException("Invalid date format.");
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-greenmail,代码行数:21,代码来源:CommandParser.java

示例7: durationFromAtoB

import java.text.DateFormat; //导入方法依赖的package包/类
public static long durationFromAtoB(String A,String B)
{
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    long diff=0;
    try
    {
        Date aDate=df.parse(A);
        Date bDate=df.parse(B);
        diff = bDate.getTime() - aDate.getTime();//这样得到的差值是毫秒级别
    }
    catch(ParseException e)
    {
        e.printStackTrace();
    }
    return diff;
}
 
开发者ID:AndroidNewbies,项目名称:Sanxing,代码行数:17,代码来源:MyDuration.java

示例8: daysDifference

import java.text.DateFormat; //导入方法依赖的package包/类
/**
 * Counts the days interval between two dates. Time component is ignored.
 * @param date1
 * @param date2
 * @return
 */
public int daysDifference(Date date1, Date date2) {
	// FIXME non è né efficiente né precisa ma funziona
	// Presa da http://stackoverflow.com/questions/13198609/java-calendar-getting-difference-between-two-dates-times-off-by-one
	try {
		// Non credo sia necessario passare per un formatter: basta azzerare i componenti di ora, minuti etc. usando Calendar
		DateFormat formatter= new SimpleDateFormat("MM/dd/yyyy");
		String truncatedDateString1 = formatter.format(date1);
		Date truncatedDate1 = formatter.parse(truncatedDateString1);
		String truncatedDateString2 = formatter.format(date2);
		Date truncatedDate2 = formatter.parse(truncatedDateString2);
		long timeDifference = truncatedDate2.getTime()- truncatedDate1.getTime();
		return Math.abs((int)(timeDifference / (24*60*60*1000)));
	} catch (ParseException e) {
		// Should never be
		log.error("Failed to compute time difference", e);
	}
	return 0;
}
 
开发者ID:xtianus,项目名称:yadaframework,代码行数:25,代码来源:YadaUtil.java

示例9: formTimeToDay

import java.text.DateFormat; //导入方法依赖的package包/类
public static String formTimeToDay(Context context, String time) {
    Calendar today = Calendar.getInstance();
    Calendar other = Calendar.getInstance();
    DateFormat df_date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    DateFormat df_time = new SimpleDateFormat("HH:mm");
    try {
        Date other_date = df_date.parse(time);
        String tm = " " + df_time.format(other_date);
        today.setTime(new Date());
        today.set(11, 0);
        today.set(12, 0);
        today.set(13, 0);
        other.setTime(other_date);
        switch ((int) Math.floor((double) (((float) (other.getTimeInMillis() - today.getTimeInMillis())) / 8.64E7f))) {
            case -1:
                return context.getString(R.string.letvutil_week_yesterday) + tm;
            case 0:
                return context.getString(R.string.letvutil_week_tody) + tm;
            case 1:
                return context.getString(R.string.letvutil_week_tomorrow) + tm;
            default:
                return new SimpleDateFormat("MM" + LetvUtils.getString(R.string.month) + "dd" + LetvUtils.getString(R.string.day) + " HH:mm").format(df_date.parse(time));
        }
    } catch (ParseException e) {
        return time;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:28,代码来源:LetvTools.java

示例10: getDate

import java.text.DateFormat; //导入方法依赖的package包/类
public Date getDate() {
	DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
	Date date = new Date();
	try
	{
		date = df.parse(createdAt);
	}
	catch (ParseException e) {
		Log.e("LOG", "ERROR", e);
	}

	return date;
}
 
开发者ID:Svyatozar,项目名称:Navalny.Pulse,代码行数:14,代码来源:Alert.java

示例11: dateUpload

import java.text.DateFormat; //导入方法依赖的package包/类
public static String dateUpload(String date) {
    if (date != null) {
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
        DateFormat plamberFormat = new SimpleDateFormat("dd.MM.yy", Locale.US);
        Date newDate = null;
        try {
            newDate = format.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return plamberFormat.format(newDate);
    } else {
        return null;
    }
}
 
开发者ID:OlegKlimenko,项目名称:Plamber-Android,代码行数:16,代码来源:Utils.java

示例12: usingDateFormatToParseDates

import java.text.DateFormat; //导入方法依赖的package包/类
@Koan
public void usingDateFormatToParseDates() throws ParseException {
    DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");
    Date date2 = dateFormat.parse("01-01-2000");
    assertEquals(date2.toString(), __);
    // What happened to the time? What do you need to change to keep the time as well?
}
 
开发者ID:linbin0107,项目名称:koans,代码行数:8,代码来源:AboutDates.java

示例13: convertStringToDate

import java.text.DateFormat; //导入方法依赖的package包/类
public Date convertStringToDate(String dateString) {
      Date formatteddate = null;
      DateFormat df = new SimpleDateFormat("YYYYMMDD HH:mm:ss.SSS");
      try{
    	  formatteddate = df.parse(dateString);
      }
      catch ( Exception ex ){
    	  return null;
      }
      return formatteddate;
}
 
开发者ID:jeanNyil,项目名称:fis-amq-producer,代码行数:12,代码来源:InformationBean.java

示例14: getDateFromDateString

import java.text.DateFormat; //导入方法依赖的package包/类
public static Date getDateFromDateString(String dateString, String format, String timeZone) throws ParseException {
    DateFormat simpleDateFormat = new SimpleDateFormat(format);
    if (null != timeZone) {
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone));
    }
    return simpleDateFormat.parse(dateString);
}
 
开发者ID:sinhaDroid,项目名称:BlogBookApp,代码行数:8,代码来源:TimeUtils.java

示例15: convertStringToFullDate

import java.text.DateFormat; //导入方法依赖的package包/类
public static Date convertStringToFullDate(String strDate) {
	DateFormat df = getDateTimeFormat(_VN_DATE_TIME_FORMAT);
	Date date = null;

	try {
		if (Validator.isNotNull(strDate)) {
			date = df.parse(strDate);
		}
	}
	catch (ParseException pe) {
		_log.error(pe);
	}

	return date;
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:16,代码来源:DateTimeUtils.java


注:本文中的java.text.DateFormat.parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。