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

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

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

DateFormat.getInstance介绍

[英]Returns a DateFormat instance for formatting and parsing dates and times in the SHORT style for the default locale.
[中]返回一个DateFormat实例,用于以默认区域设置的短样式格式化和分析日期和时间。

代码示例

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

try{
  ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), 0);
  ZipFile zf = new ZipFile(ai.sourceDir);
  ZipEntry ze = zf.getEntry("classes.dex");
  long time = ze.getTime();
  String s = SimpleDateFormat.getInstance().format(new java.util.Date(time));
  zf.close();
}catch(Exception e){
}

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

DateFormat.getInstance().format(currentTimeMillis);

代码示例来源:origin: json-path/JsonPath

public Date convert(Object src) {
    if(src == null){
      return null;
    }
    if(Date.class.isAssignableFrom(src.getClass())){
      return (Date) src;
    } else if(Long.class.isAssignableFrom(src.getClass())){
      return new Date((Long) src);
    } else if(String.class.isAssignableFrom(src.getClass())){
      try {
        return DateFormat.getInstance().parse(src.toString());
      } catch (ParseException e) {
        throw new MappingException(e);
      }
    }
    throw new MappingException("can not map a " + src.getClass() + " to " + Date.class.getName());
  }
}

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

return DateFormat.getTimeInstance().format((Date) o);
return DateFormat.getInstance().format((Date) o);

代码示例来源:origin: spring-projects/spring-data-redis

@Override
  public Date convert(byte[] source) {
    if (ObjectUtils.isEmpty(source)) {
      return null;
    }
    String value = toString(source);
    try {
      return new Date(NumberUtils.parseNumber(value, Long.class));
    } catch (NumberFormatException nfe) {
      // ignore
    }
    try {
      return DateFormat.getInstance().parse(value);
    } catch (ParseException e) {
      // ignore
    }
    throw new IllegalArgumentException(String.format("Cannot parse date out of %s", Arrays.toString(source)));
  }
}

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

CommandResponse(String sender, String contentType, int status, String page, String tokenAccessor,
  String debugInfo, String header, GfJsonObject content, String footer, boolean failedToPersist,
  Path fileToDownload) {
 this.sender = sender;
 this.contentType = contentType;
 this.status = status;
 this.page = page;
 this.tokenAccessor = tokenAccessor;
 this.debugInfo = debugInfo;
 this.data = new LegacyData(header, content, footer);
 this.when = DateFormat.getInstance().format(new java.util.Date());
 this.version = GemFireVersion.getGemFireVersion();
 this.failedToPersist = failedToPersist;
 if (fileToDownload != null) {
  this.fileToDownload = fileToDownload.toString();
 } else {
  this.fileToDownload = null;
 }
 this.isLegacy = true;
}

代码示例来源:origin: btraceio/btrace

@SuppressWarnings("DefaultCharset")
protected final void setupWriter() {
  String outputFile = settings.getOutputFile();
  if (outputFile == null || outputFile.equals("::null") || outputFile.equals("/dev/null")) return;
  if (!outputFile.equals("::stdout")) {
    String outputDir = settings.getOutputDir();
    String output = (outputDir != null ? outputDir + File.separator : "") + outputFile;
    outputFile = templateOutputFileName(output);
    infoPrint("Redirecting output to " + outputFile);
  }
  out = WRITER_MAP.get(outputFile);
  if (out == null) {
    if (outputFile.equals("::stdout")) {
      out = new PrintWriter(System.out);
    } else {
      if (settings.getFileRollMilliseconds() > 0) {
        out = new PrintWriter(new BufferedWriter(
          TraceOutputWriter.rollingFileWriter(new File(outputFile), settings)
        ));
      } else {
        out = new PrintWriter(new BufferedWriter(TraceOutputWriter.fileWriter(new File(outputFile), settings)));
      }
    }
    WRITER_MAP.put(outputFile, out);
    out.append("### BTrace Log: " + DateFormat.getInstance().format(new Date()) + "\n\n");
    startFlusher();
  }
  outputName = outputFile;
}

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

format = NumberFormat.getInstance();
} else if (arg instanceof Date) {
  format = DateFormat.getInstance();
} else {
  buffer.append(arg);

代码示例来源:origin: h2oai/h2o-2

@Override public Response serve() {
 String traces[] = new JStackCollectorTask().invokeOnAllNodes()._result;
 nodes = new StackSummary[H2O.CLOUD.size()];
 for( int i=0; i<nodes.length; i++ )
  nodes[i] = new StackSummary(H2O.CLOUD._memary[i].toString(),traces[i]);
 node_name = H2O.SELF.toString();
 cloud_name = H2O.NAME;
 time = DateFormat.getInstance().format(new Date());
 for( int i=0; i<nodes.length; i++ )
  Log.debug(Log.Tag.Sys.WATER,nodes[i].name,nodes[i].traces);
 return Response.done(this);
}

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

public void validate() throws InvalidSessionException {
  //check for stopped:
  if (isStopped()) {
    //timestamp is set, so the session is considered stopped:
    String msg = "Session with id [" + getId() + "] has been " +
        "explicitly stopped.  No further interaction under this session is " +
        "allowed.";
    throw new StoppedSessionException(msg);
  }
  //check for expiration
  if (isTimedOut()) {
    expire();
    //throw an exception explaining details of why it expired:
    Date lastAccessTime = getLastAccessTime();
    long timeout = getTimeout();
    Serializable sessionId = getId();
    DateFormat df = DateFormat.getInstance();
    String msg = "Session with id [" + sessionId + "] has expired. " +
        "Last access time: " + df.format(lastAccessTime) +
        ".  Current time: " + df.format(new Date()) +
        ".  Session timeout is set to " + timeout / MILLIS_PER_SECOND + " seconds (" +
        timeout / MILLIS_PER_MINUTE + " minutes)";
    if (log.isTraceEnabled()) {
      log.trace(msg);
    }
    throw new ExpiredSessionException(msg);
  }
}

代码示例来源:origin: h2oai/h2o-2

@Override public void execImpl() {
 ProfileCollectorTask.NodeProfile profiles[] = new ProfileCollectorTask(depth).invokeOnAllNodes()._result;
 nodes = new ProfileSummary[H2O.CLOUD.size()];
 for( int i=0; i<nodes.length; i++ )
  nodes[i] = new ProfileSummary(H2O.CLOUD._memary[i].toString(),profiles[i]);
 node_name = H2O.SELF.toString();
 cloud_name = H2O.NAME;
 time = DateFormat.getInstance().format(new Date());
 for( int i=0; i<nodes.length; i++ ) {
  Log.info(nodes[i].name);
  for (int j = 0; j < nodes[i].profile.counts.length; ++j) {
   Log.info(nodes[i].profile.counts[j]);
   Log.info(nodes[i].profile.stacktraces[j]);
  }
 }
}

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

case ValueMetaInterface.TYPE_DATE:
 try {
  data.nullIf[i] = DateFormat.getInstance().parse( meta.getValueDefault()[i] );
 } catch ( Exception e ) {

代码示例来源:origin: google/agera

.recycleWith(rowHandler)
  .forList())
.addItem(getInstance().format(new Date()), dataBindingRepositoryPresenterOf(String.class)
  .layout(R.layout.footer)
  .itemId(BR.string)

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * Converts the string to a date, using the default date format.
 *
 * @param pString the string to convert
 * @return the date
 * @see DateFormat
 * @see DateFormat#getInstance()
 */
public static Date toDate(String pString) {
  // Default
  return toDate(pString, DateFormat.getInstance());
}

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

break;
case RssInputField.COLUMN_PUB_DATE:
 valueString = item.getPubDate() == null ? "" : DateFormat.getInstance().format( item.getPubDate() );
 break;
default:

代码示例来源:origin: com.jayway.jsonpath/json-path

public Date convert(Object src) {
    if(src == null){
      return null;
    }
    if(Date.class.isAssignableFrom(src.getClass())){
      return (Date) src;
    } else if(Long.class.isAssignableFrom(src.getClass())){
      return new Date((Long) src);
    } else if(String.class.isAssignableFrom(src.getClass())){
      try {
        return DateFormat.getInstance().parse(src.toString());
      } catch (ParseException e) {
        throw new MappingException(e);
      }
    }
    throw new MappingException("can not map a " + src.getClass() + " to " + Date.class.getName());
  }
}

代码示例来源:origin: org.apache.commons/commons-text

@Test
public void testDefault() throws ParseException {
  final String formatted = DateStringLookup.INSTANCE.lookup(null);
  DateFormat.getInstance().parse(formatted); // throws ParseException
}

代码示例来源:origin: haraldk/TwelveMonkeys

@Test
public void testToDate() {
  long time = System.currentTimeMillis();
  Date now = new Date(time - time % 60000); // Default format seems to have no seconds..
  Date date = StringUtil.toDate(DateFormat.getInstance().format(now));
  assertNotNull(date);
  assertEquals(now, date);
}

代码示例来源:origin: org.apache.shiro/shiro-core

public void validate() throws InvalidSessionException {
  //check for stopped:
  if (isStopped()) {
    //timestamp is set, so the session is considered stopped:
    String msg = "Session with id [" + getId() + "] has been " +
        "explicitly stopped.  No further interaction under this session is " +
        "allowed.";
    throw new StoppedSessionException(msg);
  }
  //check for expiration
  if (isTimedOut()) {
    expire();
    //throw an exception explaining details of why it expired:
    Date lastAccessTime = getLastAccessTime();
    long timeout = getTimeout();
    Serializable sessionId = getId();
    DateFormat df = DateFormat.getInstance();
    String msg = "Session with id [" + sessionId + "] has expired. " +
        "Last access time: " + df.format(lastAccessTime) +
        ".  Current time: " + df.format(new Date()) +
        ".  Session timeout is set to " + timeout / MILLIS_PER_SECOND + " seconds (" +
        timeout / MILLIS_PER_MINUTE + " minutes)";
    if (log.isTraceEnabled()) {
      log.trace(msg);
    }
    throw new ExpiredSessionException(msg);
  }
}

代码示例来源:origin: mulesoft/mule

@Test
public void importStaticMethod() throws RegistrationException, InitialisationException {
 assertThat(evaluate("dateFormat()"), is(DateFormat.getInstance()));
}

相关文章