本文整理了Java中java.util.Date.toString()
方法的一些代码示例,展示了Date.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Date.toString()
方法的具体详情如下:
包路径:java.util.Date
类名称:Date
方法名:toString
[英]Returns a string representation of this Date. The formatting is equivalent to using a SimpleDateFormat with the format string "EEE MMM dd HH:mm:ss zzz yyyy", which looks something like "Tue Jun 22 13:07:00 PDT 1999". The current default time zone and locale are used. If you need control over the time zone or locale, use SimpleDateFormat instead.
[中]返回此日期的字符串表示形式。格式设置相当于使用一个SimpleDataFormat,其格式字符串为“EEE MMM dd HH:mm:ss zzz yyyy”,类似于“Tue Jun 22 13:07:00 PDT 1999”。将使用当前默认时区和区域设置。如果需要控制时区或区域设置,请改用SimpleDataFormat。
代码示例来源:origin: perwendel/spark
public void setExpireTimeSeconds(long expireTimeSeconds) {
customHeaders.put("Cache-Control", "private, max-age=" + expireTimeSeconds);
customHeaders.put("Expires", new Date(System.currentTimeMillis() + (expireTimeSeconds * 1000)).toString());
}
代码示例来源:origin: alibaba/nacos
private static void outPrintln(PrintStream out, String msg) {
out.println(Calendar.getInstance().getTime().toString() + " " + CLASS_INFO + " " + msg);
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public String toString() {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timestamp);
return "[" + calendar.getTime().toString() + "] " + location + File.separator + name;
}
}
代码示例来源:origin: voldemort/voldemort
private static void printProperty(String propName, String propValue) {
System.out.print(propName + "=" + propValue);
Long lValue = tryParse(propValue);
if(lValue > 0) {
Date date = new Date(lValue);
System.out.print(" [ " + date.toString() + " ] ");
}
System.out.println();
}
代码示例来源:origin: stackoverflow.com
// **** YOUR CODE **** BEGIN ****
long ts = System.currentTimeMillis();
Date localTime = new Date(ts);
String format = "yyyy/MM/dd HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
// Convert Local Time to UTC (Works Fine)
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
Date gmtTime = new Date(sdf.format(localTime));
System.out.println("Local:" + localTime.toString() + "," + localTime.getTime() + " --> UTC time:"
+ gmtTime.toString() + "," + gmtTime.getTime());
// **** YOUR CODE **** END ****
// Convert UTC to Local Time
Date fromGmt = new Date(gmtTime.getTime() + TimeZone.getDefault().getOffset(localTime.getTime()));
System.out.println("UTC time:" + gmtTime.toString() + "," + gmtTime.getTime() + " --> Local:"
+ fromGmt.toString() + "-" + fromGmt.getTime());
代码示例来源:origin: pentaho/pentaho-kettle
SimpleDateFormat daf2 = new SimpleDateFormat();
System.out.println();
Date maxdate = maxDate[i][x];
message.append( BaseMessages.getString( PKG, "TextFileCSVImportProgressDialog.Info.DateMinValue",
mindate.toString() ) );
message.append( BaseMessages.getString( PKG, "TextFileCSVImportProgressDialog.Info.DateMaxValue",
maxdate.toString() ) );
Date md = daf2.parse( minstr[i] );
message.append( BaseMessages.getString( PKG, "TextFileCSVImportProgressDialog.Info.DateExample", Const
.getDateFormats()[x], minstr[i], md.toString() ) );
} catch ( Exception e ) {
if ( log.isDetailed() ) {
代码示例来源:origin: alibaba/mdrill
private String getDateString()
{
if( format == null ){ try{ format = new SimpleDateFormat( DATE_TEMPLET, Locale.ENGLISH ); }catch( Exception e ){} }
return ( format == null ? new Date().toString() : format.format( new Date() ) );
}
代码示例来源:origin: apache/cloudstack
public static void main(String[] args) {
TimeZone localTimezone = Calendar.getInstance().getTimeZone();
TimeZone gmtTimezone = TimeZone.getTimeZone("GMT");
TimeZone estTimezone = TimeZone.getTimeZone("EST");
Date time = new Date();
System.out.println("local time :" + DateUtil.getDateDisplayString(localTimezone, time));
System.out.println("GMT time :" + DateUtil.getDateDisplayString(gmtTimezone, time));
System.out.println("EST time :" + DateUtil.getDateDisplayString(estTimezone, time));
//Test next run time. Expects interval and schedule as arguments
if (args.length == 2) {
System.out.println("Next run time: " + DateUtil.getNextRunTime(IntervalType.getIntervalType(args[0]), args[1], "GMT", time).toString());
}
}
代码示例来源:origin: knowm/XChange
public static void main(String[] args) throws IOException {
// Use the factory to get Cex.IO exchange API using default settings
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(AbucoinsExchange.class.getName());
// Interested in the public market data feed (no authentication)
MarketDataService marketDataService = exchange.getMarketDataService();
// Get the latest order book data for GHs/BTC
OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_USD);
System.out.println(
"Current Order Book size for BTC/USD: "
+ (orderBook.getAsks().size() + orderBook.getBids().size()));
System.out.println("First Ask: " + orderBook.getAsks().get(0).toString());
System.out.println("First Bid: " + orderBook.getBids().get(0).toString());
System.out.println("Timestamp: " + orderBook.getTimeStamp().toString());
// System.out.println(orderBook.toString());
}
}
代码示例来源:origin: stackoverflow.com
c.set(Calendar.MINUTE, 58);
c.set(Calendar.SECOND, 15);
Date d = c.getTime();
System.out.println("Start point: " + d.toString());
System.out.println("Nearest whole minute: " + toNearestWholeMinute(d));
System.out.println("Nearest whole hour: " + toNearestWholeHour(d));
return c.getTime();
c.set(Calendar.SECOND, 0);
return c.getTime();
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) throws ParseException {
GregorianCalendar gcal = new GregorianCalendar();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
Date start = sdf.parse("2010.01.01");
Date end = sdf.parse("2010.01.14");
gcal.setTime(start);
while (gcal.getTime().before(end)) {
gcal.add(Calendar.DAY_OF_YEAR, 1);
System.out.println( gcal.getTime().toString());
}
}
代码示例来源:origin: stackoverflow.com
import java.util.*;
import java.text.*;
class Test {
public static void main(String[] args) {
Date thisDate = null;
try {
thisDate = (new SimpleDateFormat("MM/dd/yyyy")).parse(Calendar.getInstance().getTime().toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse("2009-08-19 12:00:00");
System.out.print(date.toString());
代码示例来源:origin: commons-net/commons-net
SimpleDateFormat hackFormatter = new SimpleDateFormat(recentDateFormat.toPattern() + " yyyy",
recentDateFormat.getDateFormatSymbols());
hackFormatter.setLenient(false);
throw new ParseException(
"Timestamp '"+timestampStr+"' could not be parsed using a server time of "
+serverTime.getTime().toString(),
pp.getErrorIndex());
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Calendar then=new GregorianCalendar(year, monthOfYear, dayOfMonth);
Toast.makeText(this, then.getTime().toString(), Toast.LENGTH_LONG)
.show();
}
}
代码示例来源:origin: FudanNLP/fnlp
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String path = "./tmpdata/FNLPDATA";
String toPath = "./tmpdata/FNLPDATA/data-pos.txt";
trans(path, toPath);
System.out.println(new Date().toString());
System.out.println("Done!");
}
static void trans(String path, String toPath) throws IOException,
代码示例来源:origin: alibaba/nacos
private static void println(PrintStream out, String msg) {
out.println(Calendar.getInstance().getTime().toString() + " " + CLASS_INFO + " " + msg);
}
代码示例来源:origin: stackoverflow.com
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
Date now = new Date();
System.out.println(now.toString());
String start = dateFormat.format(now);
Date after = dateFormat.parse(start);
System.out.println(after.toString());
代码示例来源:origin: pentaho/pentaho-kettle
SimpleDateFormat daf2 = new SimpleDateFormat();
System.out.println();
Date maxdate = maxDate[i][x];
message.append( BaseMessages.getString(
PKG, "TextFileCSVImportProgressDialog.Info.DateMinValue", mindate.toString() ) );
message.append( BaseMessages.getString(
PKG, "TextFileCSVImportProgressDialog.Info.DateMaxValue", maxdate.toString() ) );
message.append( BaseMessages.getString(
PKG, "TextFileCSVImportProgressDialog.Info.DateExample", Const.getDateFormats()[x],
minstr[i], md.toString() ) );
} catch ( Exception e ) {
if ( log.isDetailed() ) {
代码示例来源:origin: apache/storm
/**
* Returns a default formatted string with fields separated by ","
*
* @return a default formatted string with fields separated by ","
*/
@Override
public String toString() {
return new Date(ts).toString() + "," + component + "," + String.valueOf(task) + ","
+ (messageId == null ? "" : messageId.toString()) + "," + values.toString();
}
}
内容来源于网络,如有侵权,请联系作者删除!