java.text.DateFormat.parse()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(247)

本文整理了Java中java.text.DateFormat.parse()方法的一些代码示例,展示了DateFormat.parse()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateFormat.parse()方法的具体详情如下:
包路径:java.text.DateFormat
类名称:DateFormat
方法名:parse

DateFormat.parse介绍

[英]Parses a date from the specified string using the rules of this date format.
[中]使用此日期格式的规则从指定字符串解析日期。

代码示例

canonical example by Tabnine

public boolean isDateExpired(String input, Date expiration) throws ParseException {
 DateFormat dateFormat = new SimpleDateFormat ("dd/MM/yyyy");
 Date date = dateFormat.parse(input);
 return date.after(expiration);
}

代码示例来源:origin: stackoverflow.com

String string = "January 2, 2010";
DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
Date date = format.parse(string);
System.out.println(date); // Sat Jan 02 00:00:00 GMT 2010

代码示例来源:origin: stackoverflow.com

String oldstring = "2011-01-18 00:00:00.0";
Date date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S").parse(oldstring);

代码示例来源:origin: stackoverflow.com

String dt = "2008-01-01";  // Start date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(dt));
c.add(Calendar.DATE, 1);  // number of days to add
dt = sdf.format(c.getTime());  // dt is now the new date

代码示例来源:origin: stackoverflow.com

// Format for input
SimpleDateFormat dateParser = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
// Parsing the date
Date date = dateParser.parse(dateTime);
// Format for output
SimpleDateFormat dateFormatter = new SimpleDateFormat("MM/dd/yyyy");
// Printing the date
System.out.println(dateFormatter.format(date));

代码示例来源:origin: stackoverflow.com

SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
String inputString1 = "23 01 1997";
String inputString2 = "27 04 1997";

try {
  Date date1 = myFormat.parse(inputString1);
  Date date2 = myFormat.parse(inputString2);
  long diff = date2.getTime() - date1.getTime();
  System.out.println ("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS));
} catch (ParseException e) {
  e.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

String time1 = "16:00:00";
String time2 = "19:00:00";

SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
Date date1 = format.parse(time1);
Date date2 = format.parse(time2);
long difference = date2.getTime() - date1.getTime();

代码示例来源:origin: stackoverflow.com

String dateStr = "04/05/2010"; 

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy"); 
Date dateObj = curFormater.parse(dateStr); 
SimpleDateFormat postFormater = new SimpleDateFormat("MMMM dd, yyyy"); 

String newDateStr = postFormater.format(dateObj);

代码示例来源:origin: stackoverflow.com

SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
formatter.setLenient(false);

Date curDate = new Date();
long curMillis = curDate.getTime();
String curTime = formatter.format(curDate);

String oldTime = "05.01.2011, 12:45";
Date oldDate = formatter.parse(oldTime);
long oldMillis = oldDate.getTime();

代码示例来源:origin: apache/hive

private static long parseToMillis(String s) {
 try {
  return DATE_FORMAT.get().parse(s).getTime();
 } catch (ParseException ex) {
  throw new RuntimeException(ex);
 }
}

代码示例来源:origin: stackoverflow.com

final DateFormat format = new SimpleDateFormat("E. M/d");
final String dateStr = "Thu. 03/01";
final Date date = format.parse(dateStr);

GregorianCalendar gregory = new GregorianCalendar();
gregory.setTime(date);

XMLGregorianCalendar calendar = DatatypeFactory.newInstance()
    .newXMLGregorianCalendar(
      gregory);

代码示例来源:origin: bluelinelabs/LoganSquare

@Override
public Calendar parse(JsonParser jsonParser) throws IOException {
  String dateString = jsonParser.getValueAsString(null);
  try {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(mDateFormat.get().parse(dateString));
    return calendar;
  } catch (ParseException e) {
    return null;
  }
}

代码示例来源:origin: apache/geode

protected boolean evaluateUntil(String timestamp) {
 try {
  return DATE_FORMAT.parse(timestamp).after(Calendar.getInstance().getTime());
 } catch (ParseException e) {
  return false;
 }
}

代码示例来源:origin: stackoverflow.com

Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, 1);
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(cal.getTime());
// Output "Wed Sep 26 14:23:28 EST 2012"

String formatted = format1.format(cal.getTime());
System.out.println(formatted);
// Output "2012-09-26"

System.out.println(format1.parse(formatted));
// Output "Wed Sep 26 00:00:00 EST 2012"

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws Exception
{
  String str = "Jun 13 2003 23:11:52.454 UTC";
  SimpleDateFormat df = new SimpleDateFormat("MMM dd yyyy HH:mm:ss.SSS zzz");
  Date date = df.parse(str);
  long epoch = date.getTime();
  System.out.println(epoch); // 1055545912454
}

代码示例来源:origin: stackoverflow.com

Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.ENGLISH);
cal.setTime(sdf.parse("Mon Mar 14 16:02:37 GMT 2011"));// all done

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws Exception {
  String target = "Thu Sep 28 20:29:30 JST 2000";
  DateFormat df = new SimpleDateFormat("EEE MMM dd kk:mm:ss z yyyy", Locale.ENGLISH);
  Date result =  df.parse(target);  
  System.out.println(result);
}

代码示例来源:origin: stackoverflow.com

DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse("23/09/2007");
long time = date.getTime();
new Timestamp(time);

代码示例来源:origin: stackoverflow.com

String input = "Thu Jun 18 20:56:02 EDT 2009";
   SimpleDateFormat parser = new SimpleDateFormat("EEE MMM d HH:mm:ss zzz yyyy");
   Date date = parser.parse(input);
   SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
   String formattedDate = formatter.format(date);
   ...

代码示例来源:origin: apache/hive

private static long parseToMillis(String s) {
 try {
  return DATE_FORMAT.get().parse(s).getTime();
 } catch (ParseException ex) {
  throw new RuntimeException(ex);
 }
}

相关文章