当前位置: 首页>>代码示例>>Java>>正文


Java SimpleDateFormat类代码示例

本文整理汇总了Java中java.text.SimpleDateFormat的典型用法代码示例。如果您正苦于以下问题:Java SimpleDateFormat类的具体用法?Java SimpleDateFormat怎么用?Java SimpleDateFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleDateFormat类属于java.text包,在下文中一共展示了SimpleDateFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: index

import java.text.SimpleDateFormat; //导入依赖的package包/类
public void index(Map<String, Object> context) throws Exception {
    Map<String, String> properties = new TreeMap<String, String>();
    StringBuilder msg = new StringBuilder();
    msg.append("Version: ");
    msg.append(Version.getVersion(Envs.class, "2.2.0"));
    properties.put("Registry", msg.toString());
    String address = NetUtils.getLocalHost();
    properties.put("Host", NetUtils.getHostName(address) + "/" + address);
    properties.put("Java", System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version"));
    properties.put("OS", System.getProperty("os.name") + " "
            + System.getProperty("os.version"));
    properties.put("CPU", System.getProperty("os.arch", "") + ", "
            + String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores");
    properties.put("Locale", Locale.getDefault().toString() + "/"
            + System.getProperty("file.encoding"));
    properties.put("Uptime", formatUptime(ManagementFactory.getRuntimeMXBean().getUptime()) 
            + " From " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date(ManagementFactory.getRuntimeMXBean().getStartTime())) 
            + " To " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date()));
    context.put("properties", properties);
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:21,代码来源:Envs.java

示例2: Test4125892

import java.text.SimpleDateFormat; //导入依赖的package包/类
/**
 * Prove that GregorianCalendar is proleptic (it used to cut off
 * at 45 BC, and not have leap years before then).
 */
public void Test4125892() {
    Locale locale = Locale.getDefault();
    if (!TestUtils.usesGregorianCalendar(locale)) {
        logln("Skipping this test because locale is " + locale);
        return;
    }

    GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance();
    DateFormat fmt = new SimpleDateFormat("MMMM d, yyyy G");
    cal.clear();
    cal.set(ERA, GregorianCalendar.BC);
    cal.set(YEAR, 81); // 81 BC is a leap year (proleptically)
    cal.set(MONTH, FEBRUARY);
    cal.set(DATE, 28);
    cal.add(DATE, 1);
    if (cal.get(DATE) != 29
            || !cal.isLeapYear(-80)) { // -80 == 81 BC
        errln("Calendar not proleptic");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:CalendarRegression.java

示例3: countDiffDay

import java.text.SimpleDateFormat; //导入依赖的package包/类
public static Integer countDiffDay(String startDate, String endDate) {
  	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  	Calendar cal = Calendar.getInstance(); 
  	long fTime = 0;
  	long oTime = 0;
      try {
	cal.setTime(sdf.parse(startDate));
       fTime = cal.getTimeInMillis();
       
       cal.setTime(sdf.parse(endDate));    
       oTime = cal.getTimeInMillis();  
} catch (ParseException e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}    

      long between_days=(oTime-fTime)/(1000*3600*24); 
  	return Integer.parseInt(String.valueOf(between_days));
  }
 
开发者ID:lpj24,项目名称:jobManage,代码行数:20,代码来源:UtilHelper.java

示例4: writeObjectToJson

import java.text.SimpleDateFormat; //导入依赖的package包/类
protected void writeObjectToJson(HttpServletResponse resp,Object obj) throws ServletException, IOException{
	resp.setHeader("Access-Control-Allow-Origin", "*");
	resp.setContentType("text/json");
	resp.setCharacterEncoding("UTF-8");
	ObjectMapper mapper=new ObjectMapper();
	mapper.setSerializationInclusion(Inclusion.NON_NULL);
	mapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS,false);
	mapper.setDateFormat(new SimpleDateFormat(Configure.getDateFormat()));
	OutputStream out = resp.getOutputStream();
	try {
		mapper.writeValue(out, obj);
	} finally {
		out.flush();
		out.close();
	}
}
 
开发者ID:youseries,项目名称:urule,代码行数:17,代码来源:WriteJsonServletHandler.java

示例5: getCurrentTime

import java.text.SimpleDateFormat; //导入依赖的package包/类
private long getCurrentTime() {
    long currentTime = 0;
    NTPUDPClient client = new NTPUDPClient();
    client.setDefaultTimeout(WAIT_FOR_SERVER_RESPONSE);
    try {
        client.open();
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM dd yyyy HH:mm:ss.SSS zzz");
        for (String server : NTP_SERVERS) {
            try {
                InetAddress ioe = InetAddress.getByName(server);
                TimeInfo info = client.getTime(ioe);
                TimeStamp ntpTime = TimeStamp.getNtpTime(info.getReturnTime());
                return ntpTime.getTime();
            } catch (Exception e2) {
                System.out.println("Can't get response from server: " + server + ".");
            }
        }
    } catch (SocketException se) {
        System.out.println("Can't open client session");
    } finally {
        client.close();
    }
    return currentTime;
}
 
开发者ID:axibase,项目名称:atsd-web-test,代码行数:25,代码来源:AdminServiceTest.java

示例6: getPhotoCaption

import java.text.SimpleDateFormat; //导入依赖的package包/类
private String getPhotoCaption(Photo photo) {
    String day = getResources().getString(R.string.pod_missing_date);
    String sep = getResources().getString(R.string.pod_caption_sep);
    String exp = getResources().getString(R.string.pod_missing_desc);


    if (photo != null) {
        SimpleDateFormat formatter = new SimpleDateFormat(getResources().getString(R.string.pod_caption_date_fmt));
        if (photo.getDate() != null) {
            day = formatter.format(photo.getDate());
        }
        if (photo.getDesc() != null) {
            exp = photo.getDesc();
        }
    }

    if (day.equals("?")) {
        return exp;
    } else{
        return day + sep + exp;
    }
}
 
开发者ID:approov,项目名称:hands-on-api-proxy,代码行数:23,代码来源:PhotoDetailFragment.java

示例7: randevuAra

import java.text.SimpleDateFormat; //导入依赖的package包/类
public void randevuAra() throws IOException
{
	SimpleDateFormat format_n=new SimpleDateFormat("dd/MM/yyyy");
	System.out.println("Bulmak istedi�iniz randevu ad�n� yerini yada tarihini girin:");
	String aranan= cin.readLine();
	
	for(Randevular obj:randevular){
	    int dogrulaAd = obj.compareTo(aranan);
	    if(dogrulaAd==0){
	    	System.out.println("----BULUNAN RANDEVU----");
	    	System.out.println(obj.getRandevuAdi()+"\n"+obj.getRandevuYeri()+"\n"
	    			 +format_n.format(obj.getRandevuTarihi()));
	    	
	    }else{
	    	System.out.println("----ARANAN RANDEVU KAYITLARDA YOK----");
	    }
		
	}
}
 
开发者ID:ozkansari,项目名称:MyCourses,代码行数:20,代码来源:KonsolRandevuUygulamasi.java

示例8: validate

import java.text.SimpleDateFormat; //导入依赖的package包/类
@Override
public boolean validate(XMLConfiguration conf) {
    value = conf.getString(paramName);
    if (value == null) {
        if (isNullOk) return true;
        return false;
    }
    try {
        DateFormat format = new SimpleDateFormat(DATE_STRING_FORMAT);
        format.parse(value);
        return true;
    } catch (ParseException e) {
        log.debug("", e);
        validateFalse();
    }
    return false;
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:18,代码来源:ConfigUtil.java

示例9: initDatetimeFormat

import java.text.SimpleDateFormat; //导入依赖的package包/类
/**
 * Initialize datetime format according to the current environment, e.g. Java 1.7 and Android.
 */
private void initDatetimeFormat() {
    String formatWithTimeZone = null;
    if (IS_ANDROID) {
        if (ANDROID_SDK_VERSION >= 18) {
            // The time zone format "ZZZZZ" is available since Android 4.3 (SDK version 18)
            formatWithTimeZone = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ";
        }
    } else if (JAVA_VERSION >= 1.7) {
        // The time zone format "XXX" is available since Java 1.7
        formatWithTimeZone = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
    }
    if (formatWithTimeZone != null) {
        this.datetimeFormat = new SimpleDateFormat(formatWithTimeZone);
        // NOTE: Use the system's default time zone (mainly for datetime formatting).
    } else {
        // Use a common format that works across all systems.
        this.datetimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        // Always use the UTC time zone as we are using a constant trailing "Z" here.
        this.datetimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
    }
}
 
开发者ID:osimloeff,项目名称:PI-Web-API-Client-Java-Android,代码行数:25,代码来源:ApiClient.java

示例10: findByDate

import java.text.SimpleDateFormat; //导入依赖的package包/类
private void findByDate(String param){
    SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
    SimpleDateFormat df2 = new SimpleDateFormat("dd-MMM-yyyy");
    LastModifiedFileComparator c = new LastModifiedFileComparator();
    
    Date file = new Date();
    String d = df.format(file);
    sorted.clear();

    List<File> l1 = new ArrayList<>();
    toSort.stream().filter((image) -> ( df2.format(new File(image).lastModified()).equals(d))).forEach((image) -> {
        l1.add(new File(image));
    });

    List<File> f = c.sort(l1);
    f.forEach(x ->{
        sorted.add(x.getAbsolutePath());
    });
}
 
开发者ID:Obsidiam,项目名称:joanne,代码行数:20,代码来源:Sorter.java

示例11: testGetTimeData

import java.text.SimpleDateFormat; //导入依赖的package包/类
public void testGetTimeData() throws Exception {
	initializeModel();

	DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS Z");
	dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));

		double timeStep = model.getTimeStep();
		assertEquals(24 * 3600.0, timeStep);

		String timeUnits = model.getTimeUnits();
		assertEquals("seconds since 1970-01-01 00:00:00.0 00:00", timeUnits);

		double startTime = model.getStartTime();
		assertEquals("2012-01-01 00:00:00 000 +0000", dateFormat.format((long) startTime * 1000));
		assertEquals("2012-01-01 00:00:00 000 +0000", dateFormat.format(Time.mjdToMillies(TimeUtils.udUnitsTimeToMjd(startTime, timeUnits))));

		double endTime = model.getEndTime();
		assertEquals("2012-01-21 00:00:00 000 +0000", dateFormat.format((long) endTime * 1000));
		assertEquals("2012-01-21 00:00:00 000 +0000", dateFormat.format(Time.mjdToMillies(TimeUtils.udUnitsTimeToMjd(endTime, timeUnits))));

		assertEquals(model.getStartTime(), model.getCurrentTime());
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:23,代码来源:WflowBmiBridgeTest.java

示例12: getInstance

import java.text.SimpleDateFormat; //导入依赖的package包/类
private DateFormat getInstance(int dateStyle, int timeStyle, Locale locale) {
    if (locale == null) {
        throw new NullPointerException();
    }

    SimpleDateFormat sdf = new SimpleDateFormat("", locale);
    Calendar cal = sdf.getCalendar();
    try {
        String pattern = LocaleProviderAdapter.forType(type)
            .getLocaleResources(locale).getDateTimePattern(timeStyle, dateStyle,
                                                           cal);
        sdf.applyPattern(pattern);
    } catch (MissingResourceException mre) {
        // Specify the fallback pattern
        sdf.applyPattern("M/d/yy h:mm a");
    }

    return sdf;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:DateFormatProviderImpl.java

示例13: testEquals

import java.text.SimpleDateFormat; //导入依赖的package包/类
/**
 * Tests the equals() method.
 */
public void testEquals() {
    
    IntervalCategoryLabelGenerator g1 = new IntervalCategoryLabelGenerator();
    IntervalCategoryLabelGenerator g2 = new IntervalCategoryLabelGenerator();
    assertTrue(g1.equals(g2));
    assertTrue(g2.equals(g1));
    
    g1 = new IntervalCategoryLabelGenerator("{3} - {4}", new DecimalFormat("0.000"));
    assertFalse(g1.equals(g2));
    g2 = new IntervalCategoryLabelGenerator("{3} - {4}", new DecimalFormat("0.000"));
    assertTrue(g1.equals(g2));
    
    g1 = new IntervalCategoryLabelGenerator("{3} - {4}", new SimpleDateFormat("d-MMM"));
    assertFalse(g1.equals(g2));
    g2 = new IntervalCategoryLabelGenerator("{3} - {4}", new SimpleDateFormat("d-MMM"));
    assertTrue(g1.equals(g2));
    
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:IntervalCategoryLabelGeneratorTests.java

示例14: initDatabase

import java.text.SimpleDateFormat; //导入依赖的package包/类
@PostConstruct
 private void initDatabase() throws ParseException {
	
	Ciudadano c1 = new Ciudadano("Ramon", "Sobrino Llorca", "[email protected]",
			new SimpleDateFormat("yyyy-MM-dd").parse("1990-02-02"), "Oviedo", "Española", "71664900", "123456");
	Ciudadano c2 = new Ciudadano("Pablo", "Garcia", "[email protected]",
			new SimpleDateFormat("yyyy-MM-dd").parse("1995-10-31"), "Oviedo", "Española", "79845632", "111111");
	Ciudadano c3 = new Ciudadano("Javier", "Fernandez", "[email protected]",
			new SimpleDateFormat("yyyy-MM-dd").parse("1992-02-02"), "Oviedo", "Española", "78945612", "999999");
	Ciudadano c4 = new Ciudadano("Benjy", "Rojas", "[email protected]",
			new SimpleDateFormat("yyyy-MM-dd").parse("1993-02-02"), "Oviedo", "Española", "78945612", "222222");
	repository.save(c1);
	repository.save(c2);
	repository.save(c3);
	repository.save(c4);
}
 
开发者ID:Arquisoft,项目名称:participants1b,代码行数:17,代码来源:DatabaseLoader.java

示例15: getTimeAfterHeadBlockTime

import java.text.SimpleDateFormat; //导入依赖的package包/类
public String getTimeAfterHeadBlockTime(int diffInMilSec) {
    DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    try {
        Date date = sdf.parse( this.headBlockTime);

        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add( Calendar.MILLISECOND, diffInMilSec);
        date = c.getTime();

        return sdf.format(date);

    } catch (ParseException e) {
        e.printStackTrace();
        return this.headBlockTime;
    }
}
 
开发者ID:mithrilcoin-io,项目名称:EosCommander,代码行数:18,代码来源:EosChainInfo.java


注:本文中的java.text.SimpleDateFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。