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

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

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

SimpleDateFormat.<init>介绍

[英]Constructs a new SimpleDateFormat for formatting and parsing dates and times in the SHORT style for the user's default locale. See "Be wary of the default locale".
[中]构造一个新的SimpleDataFormat,用于以短样式为用户的默认区域设置格式化和解析日期和时间。请参阅“{$0$}”。

代码示例

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: alibaba/druid

public static String toString(java.util.Date date) {
  if (date == null) {
    return null;
  }
  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  return format.format(date);
}

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

// Create an instance of SimpleDateFormat used for formatting 
// the string representation of date (month/day/year)
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

// Get the date today using Calendar object.
Date today = Calendar.getInstance().getTime();        
// Using DateFormat format method we can create a string 
// representation of a date with the defined format.
String reportDate = df.format(today);

// Print what date is today!
System.out.println("Report Date: " + reportDate);

代码示例来源: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: Netflix/eureka

public static String getCurrentTimeAsString() {
    SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
    return format.format(new Date());
  }
}

代码示例来源:origin: jenkinsci/jenkins

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());
}

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

private static void printJobStatusMessages(List<JobStatusMessage> jobs) {
  SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
  Comparator<JobStatusMessage> startTimeComparator = (o1, o2) -> (int) (o1.getStartTime() - o2.getStartTime());
  Comparator<Map.Entry<JobStatus, List<JobStatusMessage>>> statusComparator =
    (o1, o2) -> String.CASE_INSENSITIVE_ORDER.compare(o1.getKey().toString(), o2.getKey().toString());
  Map<JobStatus, List<JobStatusMessage>> jobsByState = jobs.stream().collect(Collectors.groupingBy(JobStatusMessage::getJobState));
  jobsByState.entrySet().stream()
    .sorted(statusComparator)
    .map(Map.Entry::getValue).flatMap(List::stream).sorted(startTimeComparator)
    .forEachOrdered(job ->
      System.out.println(dateFormat.format(new Date(job.getStartTime()))
        + " : " + job.getJobId() + " : " + job.getJobName()
        + " (" + job.getJobState() + ")"));
}

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

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();  
}

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

Calendar cal = new GregorianCalendar();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
dateFormat.setTimeZone(cal.getTimeZone());
System.out.println(dateFormat.format(cal.getTime()));

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

String newstring = new SimpleDateFormat("yyyy-MM-dd").format(date);
System.out.println(newstring); // 2011-01-18

代码示例来源: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: apache/incubator-dubbo

@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;
  }
};

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

@Test
public void testCalendarTimezoneRespected() {
  final Calendar cal = Calendar.getInstance(timeZone);
  final SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);
  sdf.setTimeZone(timeZone);
  final String expectedValue = sdf.format(cal.getTime());
  final String actualValue = FastDateFormat.getInstance(PATTERN, this.timeZone).format(cal);
  assertEquals(expectedValue, actualValue);
}

代码示例来源: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: alibaba/fastjson

public void write(JSONSerializer serializer, Object object, BeanContext context) throws IOException {
  SerializeWriter out = serializer.out;
  String format = context.getFormat();
  Calendar calendar = (Calendar) object;
  if (format.equals("unixtime")) {
    long seconds = calendar.getTimeInMillis() / 1000L;
    out.writeInt((int) seconds);
    return;
  }
  DateFormat dateFormat = new SimpleDateFormat(format);
  if (dateFormat == null) {
    dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, serializer.locale);
    dateFormat.setTimeZone(serializer.timeZone);
  }
  String text = dateFormat.format(calendar.getTime());
  out.writeString(text);
}

代码示例来源: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 class Foo
{
  // SimpleDateFormat is not thread-safe, so give one to each thread
  private static final ThreadLocal<SimpleDateFormat> formatter = new ThreadLocal<SimpleDateFormat>(){
    @Override
    protected SimpleDateFormat initialValue()
    {
      return new SimpleDateFormat("yyyyMMdd HHmm");
    }
  };

  public String formatIt(Date date)
  {
    return formatter.get().format(date);
  }
}

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

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()) );

代码示例来源: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

相关文章

SimpleDateFormat类方法