public class MainClass { public static void main(String[] args) { java.util.Date utilDate = new java.util.Date(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime()); System.out.println("utilDate:" + utilDate); System.out.println("sqlDate:" + sqlDate); } }
private static String clientDateString() { TimeZone tz = TimeZone.getTimeZone("UTC"); DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); df.setTimeZone(tz); // strip timezone return df.format(new Date()); }
public static String getCurrentTimeAsString() { SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); return format.format(new Date()); } }
SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT")); //Local time zone SimpleDateFormat dateFormatLocal = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss"); //Time in GMT return dateFormatLocal.parse( dateFormatGmt.format(new Date()) );
public static String getDaysAgo(int interval) { Date date = new Date(); long time = date.getTime() / 1000L - (long)(interval * 60 * 60 * 24); date.setTime(time * 1000L); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { return format.format(date); } catch (Exception var6) { System.out.println(var6.getMessage()); return ""; } }
private HeapDump renameHeapdump(HeapDump heapDump) { String fileName = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss_SSS'.hprof'", Locale.US).format(new Date()); File newFile = new File(heapDump.heapDumpFile.getParent(), fileName); boolean renamed = heapDump.heapDumpFile.renameTo(newFile); if (!renamed) { CanaryLog.d("Could not rename heap dump file %s to %s", heapDump.heapDumpFile.getPath(), newFile.getPath()); } return heapDump.buildUpon().heapDumpFile(newFile).build(); }
/** * Returns the time after which a task should run again. */ @Override public Date nextExecutionTime(TriggerContext triggerContext) { Date lastExecution = triggerContext.lastScheduledExecutionTime(); Date lastCompletion = triggerContext.lastCompletionTime(); if (lastExecution == null || lastCompletion == null) { return new Date(System.currentTimeMillis() + this.initialDelay); } if (this.fixedRate) { return new Date(lastExecution.getTime() + this.period); } return new Date(lastCompletion.getTime() + this.period); }
/** * Renames file for backup. * * @param file File. * @return File. */ private static File renameToBak(File file) { DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss"); if (file.exists() && !file.renameTo(new File(file.getAbsolutePath() + "." + fmt.format(new Date()) + ".bak"))) exit("Failed to rename file '" + file.getPath() + "'.", null); return file; }
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); try { Date date = new Date(); String datetime = dateFormat.format(date); System.out.println("Current Date Time : " + datetime); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); }
public void initLog(File logFilePath) throws IOException { RedwoodConfiguration.empty() .handlers(RedwoodConfiguration.Handlers.chain( RedwoodConfiguration.Handlers.showAllChannels(), RedwoodConfiguration.Handlers.stderr), RedwoodConfiguration.Handlers.file(logFilePath.toString()) ).apply(); // fh.setFormatter(new NewlineLogFormatter()); System.out.println("Starting Ssurgeon log, at "+logFilePath.getAbsolutePath()+" date=" + DateFormat.getDateInstance(DateFormat.FULL).format(new Date())); log.info("Starting Ssurgeon log, date=" + DateFormat.getDateInstance(DateFormat.FULL).format(new Date())); }
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); Date strDate = sdf.parse(valid_until); if (new Date().after(strDate)) { catalog_outdated = 1; }
@Override public Date fromString(String string) { try { return new Date( new SimpleDateFormat(DATE_FORMAT).parse( string ).getTime() ); } catch ( ParseException pe) { throw new HibernateException( "could not parse date string" + string, pe ); } }
@Override public Object decode(Object jv) throws IOException { if (jv instanceof String) { try { return new SimpleDateFormat(DATE_FORMAT).parse((String) jv); } catch (ParseException e) { throw new IllegalArgumentException(e.getMessage(), e); } } if (jv instanceof Number) { return new Date(((Number) jv).longValue()); } return (Date) null; } };
Date now = new Date(); // java.util.Date, NOT java.sql.Date or java.sql.Timestamp! String format1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.ENGLISH).format(now); String format2 = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH).format(now); String format3 = new SimpleDateFormat("yyyyMMddHHmmss", Locale.ENGLISH).format(now); System.out.println(format1); System.out.println(format2); System.out.println(format3);
public static Date getWeekAgo() { Date date = new Date(); long time = date.getTime() / 1000L - 604800L; date.setTime(time * 1000L); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { date = format.parse(format.format(date)); } catch (Exception var5) { System.out.println(var5.getMessage()); } return date; }
private File getLogDir(Bundle extras) { File result=(File)extras.getSerializable(EXTRA_LOG_DIR); if (result==null) { String logDirName= "autofilllogger_"+ new SimpleDateFormat("yyyyMMdd'-'HHmmss").format(new Date()); result=new File(getExternalCacheDir(), logDirName); result.mkdirs(); extras.putSerializable(EXTRA_LOG_DIR, result); } return(result); } }
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { System.out.println("开始执行过滤器"); Long start = new Date().getTime(); filterChain.doFilter(servletRequest, servletResponse); System.out.println("【过滤器】耗时 " + (new Date().getTime() - start)); System.out.println("结束执行过滤器"); }