java.text.SimpleDateFormat.applyPattern()方法的使用及代码示例

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

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

SimpleDateFormat.applyPattern介绍

[英]Changes the pattern of this simple date format to the specified pattern which uses non-localized pattern characters.
[中]将此简单日期格式的模式更改为使用非本地化模式字符的指定模式。

代码示例

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

final String OLD_FORMAT = "dd/MM/yyyy";
final String NEW_FORMAT = "yyyy/MM/dd";

// August 12, 2010
String oldDateString = "12/08/2010";
String newDateString;

SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
Date d = sdf.parse(oldDateString);
sdf.applyPattern(NEW_FORMAT);
newDateString = sdf.format(d);

代码示例来源:origin: org.testng/testng

static String timeAsGmt() {
 SimpleDateFormat sdf = new SimpleDateFormat();
 sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
 sdf.applyPattern("dd MMM yyyy HH:mm:ss z");
 return sdf.format(Calendar.getInstance().getTime());
}

代码示例来源:origin: alibaba/canal

private Date parseDate(String str, String[] parsePatterns, Locale locale) throws ParseException {
    if ((str == null) || (parsePatterns == null)) {
      throw new IllegalArgumentException("Date and Patterns must not be null");
    }

    SimpleDateFormat parser = null;
    ParsePosition pos = new ParsePosition(0);

    for (int i = 0; i < parsePatterns.length; i++) {
      if (i == 0) {
        parser = new SimpleDateFormat(parsePatterns[0], locale);
      } else {
        parser.applyPattern(parsePatterns[i]);
      }
      pos.setIndex(0);
      Date date = parser.parse(str, pos);
      if ((date != null) && (pos.getIndex() == str.length())) {
        return date;
      }
    }

    throw new ParseException("Unable to parse the date: " + str, -1);
  }
}

代码示例来源:origin: pentaho/pentaho-kettle

public String buildFilename( String fileName, int stepnr, int splitnr ) {
 SimpleDateFormat daf = new SimpleDateFormat();
 // Replace possible environment variables...
 String retval = fileName;
 Date now = new Date();
 if ( dateInFilename ) {
  daf.applyPattern( "yyyMMdd" );
  String d = daf.format( now );
  retval += "_" + d;
 }
 if ( timeInFilename ) {
  daf.applyPattern( "HHmmss" );
  String t = daf.format( now );
  retval += "_" + t;
 }
 if ( stepNrInFilename ) {
  retval += "_" + stepnr;
 }
 if ( splitEvery > 0 ) {
  retval += "_" + splitnr;
 }
 if ( extension != null && extension.length() != 0 ) {
  retval += "." + extension;
 }
 return retval;
}

代码示例来源:origin: pentaho/pentaho-kettle

public String buildFilename( VariableSpace space, int stepnr ) {
 SimpleDateFormat daf = new SimpleDateFormat();
 // Replace possible environment variables...
 String retval = space.environmentSubstitute( fileName );
 Date now = new Date();
 if ( dateInFilename ) {
  daf.applyPattern( "yyyMMdd" );
  String d = daf.format( now );
  retval += "_" + d;
 }
 if ( timeInFilename ) {
  daf.applyPattern( "HHmmss" );
  String t = daf.format( now );
  retval += "_" + t;
 }
 if ( stepNrInFilename ) {
  retval += "_" + stepnr;
 }
 if ( extension != null && extension.length() != 0 ) {
  retval += "." + extension;
 }
 return retval;
}

代码示例来源:origin: pentaho/pentaho-kettle

public String buildFilename( VariableSpace space, int stepnr ) throws KettleStepException {
 SimpleDateFormat daf = new SimpleDateFormat();
 // Replace possible environment variables...
 String retval = getFilename( space );
 Date now = new Date();
 if ( dateInFilename ) {
  daf.applyPattern( "yyyMMdd" );
  String d = daf.format( now );
  retval += "_" + d;
 }
 if ( timeInFilename ) {
  daf.applyPattern( "HHmmss" );
  String t = daf.format( now );
  retval += "_" + t;
 }
 if ( stepNrInFilename ) {
  retval += "_" + stepnr;
 }
 if ( extension != null && extension.length() != 0 ) {
  retval += "." + extension;
 }
 return retval;
}

代码示例来源:origin: xalan/xalan

/**
 *  Get the full name or abbreviation of the month or day.
 */
private static String getNameOrAbbrev(String in, 
                   String[] formatsIn,
                   String formatOut)
 throws ParseException
{
 for (int i = 0; i <formatsIn.length; i++) // from longest to shortest.
 {
  try
  {
   SimpleDateFormat dateFormat = new SimpleDateFormat(formatsIn[i], Locale.ENGLISH);
   dateFormat.setLenient(false);
   Date dt = dateFormat.parse(in);          
   dateFormat.applyPattern(formatOut);
   return dateFormat.format(dt);
  }
  catch (ParseException pe)
  {
  }
 }
 return "";
}
/**

代码示例来源:origin: pentaho/pentaho-kettle

public static Date str2dat( String arg0, String arg1, String val ) throws KettleValueException {
 SimpleDateFormat df = new SimpleDateFormat();
 DateFormatSymbols dfs = new DateFormatSymbols();
 if ( arg1 != null ) {
  dfs.setLocalPatternChars( arg1 );
 }
 if ( arg0 != null ) {
  df.applyPattern( arg0 );
 }
 try {
  return df.parse( val );
 } catch ( Exception e ) {
  throw new KettleValueException( "TO_DATE Couldn't convert String to Date " + e.toString() );
 }
}

代码示例来源:origin: pentaho/pentaho-kettle

public String buildFilename( VariableSpace space, int stepnr, int splitnr ) {
 SimpleDateFormat daf = new SimpleDateFormat();
  daf.applyPattern( date_time_format );
  String dt = daf.format( now );
  retval += dt;
 } else {
  if ( dateInFilename ) {
   daf.applyPattern( "yyyMMdd" );
   String d = daf.format( now );
   retval += "_" + d;
   daf.applyPattern( "HHmmss" );
   String t = daf.format( now );
   retval += "_" + t;

代码示例来源:origin: pentaho/pentaho-kettle

public String buildFilename( VariableSpace space, int stepnr, int splitnr ) {
 SimpleDateFormat daf = new SimpleDateFormat();
  daf.applyPattern( date_time_format );
  String dt = daf.format( now );
  retval += dt;
 } else {
  if ( dateInFilename ) {
   daf.applyPattern( "yyyMMdd" );
   String d = daf.format( now );
   retval += "_" + d;
   daf.applyPattern( "HHmmss" );
   String t = daf.format( now );
   retval += "_" + t;

代码示例来源:origin: commons-lang/commons-lang

SimpleDateFormat parser = new SimpleDateFormat();
parser.setLenient(lenient);
ParsePosition pos = new ParsePosition(0);
  parser.applyPattern(pattern);
  pos.setIndex(0);

代码示例来源:origin: pentaho/pentaho-kettle

final SimpleDateFormat daf = new SimpleDateFormat();
Date now = new Date();
 daf.applyPattern( datetime_folder );
 String dt = daf.format( now );
 retval += dt;
} else {
 if ( add_date ) {
  daf.applyPattern( "yyyyMMdd" );
  String d = daf.format( now );
  retval += "_" + d;
  daf.applyPattern( "HHmmssSSS" );
  String t = daf.format( now );
  retval += "_" + t;

代码示例来源:origin: pentaho/pentaho-kettle

public String buildFilename( VariableSpace space, int stepnr, int splitnr, boolean ziparchive ) {
 SimpleDateFormat daf = new SimpleDateFormat();
 DecimalFormat df = new DecimalFormat( "00000" );
  daf.applyPattern( date_time_format );
  String dt = daf.format( now );
  retval += dt;
 } else {
  if ( dateInFilename ) {
   daf.applyPattern( "yyyyMMdd" );
   String d = daf.format( now );
   retval += "_" + d;
   daf.applyPattern( "HHmmss" );
   String t = daf.format( now );
   retval += "_" + t;

代码示例来源:origin: pentaho/pentaho-kettle

SimpleDateFormat daf = new SimpleDateFormat();
Date now = new Date();
 daf.applyPattern( date_time_format );
 String dt = daf.format( now );
 retval += dt;
} else {
 if ( adddate ) {
  daf.applyPattern( "yyyyMMdd" );
  String d = daf.format( now );
  retval += "_" + d;
  daf.applyPattern( "HHmmssSSS" );
  String t = daf.format( now );
  retval += "_" + t;

代码示例来源:origin: commons-httpclient/commons-httpclient

String format = (String) formatIter.next();            
if (dateParser == null) {
  dateParser = new SimpleDateFormat(format, Locale.US);
  dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
} else {
  dateParser.applyPattern(format);

代码示例来源:origin: pentaho/pentaho-kettle

SimpleDateFormat daf = new SimpleDateFormat();
Date now = new Date();
 daf.applyPattern( date_time_format );
 String dt = daf.format( now );
 retval += dt;
} else {
 if ( adddate ) {
  daf.applyPattern( "yyyyMMdd" );
  String d = daf.format( now );
  retval += "_" + d;
  daf.applyPattern( "HHmmssSSS" );
  String t = daf.format( now );
  retval += "_" + t;

代码示例来源:origin: pentaho/pentaho-kettle

SimpleDateFormat daf = new SimpleDateFormat();
Date now = new Date();
 daf.applyPattern( getDateTimeFormat() );
 String dt = daf.format( now );
 retval += dt;
} else {
 if ( isAddDate() ) {
  daf.applyPattern( "yyyyMMdd" );
  String d = daf.format( now );
  retval += "_" + d;
  daf.applyPattern( "HHmmssSSS" );
  String t = daf.format( now );
  retval += "_" + t;

代码示例来源:origin: commons-httpclient/commons-httpclient

String format = (String) formatIter.next();            
if (dateParser == null) {
  dateParser = new SimpleDateFormat(format, Locale.US);
  dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
  dateParser.set2DigitYearStart(startDate);
} else {
  dateParser.applyPattern(format);

代码示例来源:origin: pentaho/pentaho-kettle

SimpleDateFormat daf = new SimpleDateFormat();
Date now = new Date();
 daf.applyPattern( DateFormat );
 String dt = daf.format( now );
 shortfilename += dt;
  daf.applyPattern( getMovedDateTimeFormat() );
  String dt = daf.format( now );
  shortfilename += dt;
 } else {
  if ( isAddMovedDate() ) {
   daf.applyPattern( "yyyyMMdd" );
   String d = daf.format( now );
   shortfilename += "_" + d;
   daf.applyPattern( "HHmmssSSS" );
   String t = daf.format( now );
   shortfilename += "_" + t;

代码示例来源:origin: pentaho/pentaho-kettle

SimpleDateFormat daf = new SimpleDateFormat();
Date now = new Date();
 daf.applyPattern( DateFormat );
 String dt = daf.format( now );
 shortfilename += dt;
  daf.applyPattern( getMovedDateTimeFormat() );
  String dt = daf.format( now );
  shortfilename += dt;
 } else {
  if ( isAddMovedDate() ) {
   daf.applyPattern( "yyyyMMdd" );
   String d = daf.format( now );
   shortfilename += "_" + d;
   daf.applyPattern( "HHmmssSSS" );
   String t = daf.format( now );
   shortfilename += "_" + t;

相关文章

SimpleDateFormat类方法