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


Java SimpleDateFormat.applyPattern方法代码示例

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


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

示例1: getNameOrAbbrev

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
 *  Get the full name or abbreviation of the month or day.
 */
private static String getNameOrAbbrev(String in,
                                     String[] formatsIn,
                                     String formatOut)
  throws ParseException
{
  for (int i = 0; i <formatsIn.length; i++) // from longest to shortest.
  {
    try
    {
      SimpleDateFormat dateFormat = new SimpleDateFormat(formatsIn[i], Locale.ENGLISH);
      dateFormat.setLenient(false);
      Date dt = dateFormat.parse(in);
      dateFormat.applyPattern(formatOut);
      return dateFormat.format(dt);
    }
    catch (ParseException pe)
    {
    }
  }
  return "";
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:ExsltDatetime.java

示例2: 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:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:DateFormatProviderImpl.java

示例3: parse

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
protected static final Date parse(SimpleDateFormat parser, ParsePosition pos, String parsePattern, String txt) {
	String pattern = parsePattern;
	if (parsePattern.endsWith("ZZ")) {
		pattern = pattern.substring(0, pattern.length() - 1);
	}
	parser.applyPattern(pattern);
	pos.setIndex(0);
	String str2 = txt;
	if (parsePattern.endsWith("ZZ")) {
		str2 = txt.replaceAll("([-+][0-9][0-9]):([0-9][0-9])$", "$1$2");
	}
	final Date date = parser.parse(str2, pos);
	if (date != null && pos.getIndex() == str2.length()) {
		return date;
	}
	return null;
}
 
开发者ID:berkesa,项目名称:datatree,代码行数:18,代码来源:AbstractConverterSet.java

示例4: dateFormatter

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
 * Formats and converts a date value into string representation in the
 * desired new date format
 *
 * @param inputValue
 *            the date value in old format
 * @param oldFormat
 *            the date format of the date passed in {@code inputValue}
 * @param newFormat
 *            the desired date format
 * @return string representation of date in new date format
 *         <p>
 *         the method returns null if any parameter is null
 * @throws ParseException
 *             if the date value passed in {@code inputValue} does not match
 *             the {@code oldFormat}
 */
public static String dateFormatter(String inputValue, String oldFormat, String newFormat) {
    if (inputValue == null || oldFormat == null || newFormat == null)
        return null;
    String newDateString = null;
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(oldFormat);
        sdf.setLenient(false);
        Date date = null;

        date = sdf.parse(inputValue);

        sdf.applyPattern(newFormat);
        newDateString = sdf.format(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return newDateString;
}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:36,代码来源:DateFunctions.java

示例5: parseDate

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public static Date parseDate(String timestampStr, List<String> dateFormats, String timezone)
    throws ParseException {
  Date date = null;
  SimpleDateFormat sdf = new SimpleDateFormat();
  for (String s : dateFormats) {
    sdf.applyPattern(s);
    if (timezone != null && !timezone.isEmpty()) {
      sdf.setTimeZone(TimeZone.getTimeZone(timezone));
    }
    try {
      date = sdf.parse(timestampStr);
    } catch (ParseException ignored) {
      //do nothing
    }
  }
  if (date == null) {
    throw new ParseException(timestampStr, 0);
  }
  return date;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:21,代码来源:LocalDateUtil.java

示例6: getDays

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
private List<Day> getDays(Elements tableHeaderCells) throws ParseException {
    List<Day> days = new ArrayList<>();

    for (int i = 2; i < 7; i++) {
        String[] dayHeaderCell = tableHeaderCells.get(i).html().split("<br>");

        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy", Locale.ROOT);
        Date d = sdf.parse(dayHeaderCell[1].trim());
        sdf.applyPattern("yyyy-MM-dd");

        Day day = new Day();
        day.setDayName(dayHeaderCell[0]);
        day.setDate(sdf.format(d));

        if (tableHeaderCells.get(i).hasClass("free-day")) {
            day.setFreeDay(true);
            day.setFreeDayName(dayHeaderCell[2]);
        }

        days.add(day);
    }

    return days;
}
 
开发者ID:wulkanowy,项目名称:wulkanowy,代码行数:25,代码来源:Timetable.java

示例7: downloadFromNoaa

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
 *
 * @param date 				date of the shape file to download
 * @param outputFolder 		ouput folder destination
 * @return
 */
public File downloadFromNoaa(Date date,String outputFolder){
	SimpleDateFormat df=new SimpleDateFormat();
	df.applyPattern(TOKEN_DATE);
	String fileName=noaaFileName.replace(TOKEN_DATE,df.format(date));

	df.applyPattern(TOKEN_YEAR);
	String strurl=noaaBaseUrl.replace(TOKEN_YEAR,df.format(date))+fileName;
	return download(strurl,outputFolder+File.separator+fileName);
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:16,代码来源:IceHttpClient.java

示例8: downloadFromMasie

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
 *
 * @param date 				date of the shape file to download
 * @param outputFolder 		ouput folder destination
 * @return
 */
public File downloadFromMasie(Date date,String outputFolder){
	SimpleDateFormat df=new SimpleDateFormat();
	df.applyPattern(TOKEN_DATE);
	String fileName=masieFileName.replace(TOKEN_DATE,df.format(date));

	df.applyPattern(TOKEN_YEAR);
	String strurl=masieBaseUrl.replace(TOKEN_YEAR,df.format(date))+fileName;
	return download(strurl,outputFolder+File.separator+fileName);
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:16,代码来源:IceHttpClient.java

示例9: showInitialReleaseDate

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
private void showInitialReleaseDate(Date date) {
    String pattern = "dd MMM yyyy";
    SimpleDateFormat dateFormat = new SimpleDateFormat();
    try {
        dateFormat.applyPattern(pattern);
        String formattedDate = dateFormat.format(date);
        mInitialReleaseDate.setText(formattedDate);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:Joel-Raju,项目名称:gamer-inside,代码行数:12,代码来源:GameDetailFragment.java

示例10: FormatDate

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
 * Converts and formats an instant into a string of date with the specified pattern.
 *
 * @see SimpleDateFormat
 *
 * @param date  date to format
 * @param pattern format of the date e.g. MM/DD/YYYY or MMM d, yyyy
 * @return  formatted date
 */
@SimpleFunction
public static String FormatDate(Calendar date, String pattern) {
  SimpleDateFormat formatdate = new SimpleDateFormat();
  if (pattern.length() == 0) {
    formatdate.applyPattern("MMM d, yyyy");
  } else {
    formatdate.applyPattern(pattern);
  }
    return formatdate.format(date.getTime());
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:20,代码来源:Dates.java

示例11: parseDateWithLeniency

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
 * <p>Parses a string representing a date by trying a variety of different parsers.</p>
 * 
 * <p>The parse will try each parse pattern in turn.
 * A parse is only deemed successful if it parses the whole of the input string.
 * If no parse patterns match, a ParseException is thrown.</p>
 * 
 * @param str  the date to parse, not null
 * @param parsePatterns  the date format patterns to use, see SimpleDateFormat, not null
 * @param lenient Specify whether or not date/time parsing is to be lenient.
 * @return the parsed date
 * @throws IllegalArgumentException if the date string or pattern array is null
 * @throws ParseException if none of the date patterns were suitable
 * @see java.util.Calender#isLenient()
 */
private static Date parseDateWithLeniency(String str, String[] parsePatterns,
        boolean lenient) throws ParseException {
    if (str == null || parsePatterns == null) {
        throw new IllegalArgumentException("Date and Patterns must not be null");
    }
    
    SimpleDateFormat parser = new SimpleDateFormat();
    parser.setLenient(lenient);
    ParsePosition pos = new ParsePosition(0);
    for (int i = 0; i < parsePatterns.length; i++) {

        String pattern = parsePatterns[i];

        // LANG-530 - need to make sure 'ZZ' output doesn't get passed to SimpleDateFormat
        if (parsePatterns[i].endsWith("ZZ")) {
            pattern = pattern.substring(0, pattern.length() - 1);
        }
        
        parser.applyPattern(pattern);
        pos.setIndex(0);

        String str2 = str;
        // LANG-530 - need to make sure 'ZZ' output doesn't hit SimpleDateFormat as it will ParseException
        if (parsePatterns[i].endsWith("ZZ")) {
            int signIdx  = indexOfSignChars(str2, 0);
            while (signIdx >=0) {
                str2 = reformatTimezone(str2, signIdx);
                signIdx = indexOfSignChars(str2, ++signIdx);
            }
        }

        Date date = parser.parse(str2, pos);
        if (date != null && pos.getIndex() == str2.length()) {
            return date;
        }
    }
    throw new ParseException("Unable to parse the date: " + str, -1);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:54,代码来源:DateUtils.java

示例12: createDate

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
private static String createDate(Date date, String defaultFormat, Boolean utc) {
    SimpleDateFormat gmtFormat = new SimpleDateFormat();
    gmtFormat.applyPattern(defaultFormat);
    TimeZone gmtTime = (utc) ? TimeZone.getTimeZone("GMT") : TimeZone.getDefault();
    gmtFormat.setTimeZone(gmtTime);
    return gmtFormat.format(date);
}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:8,代码来源:ODateUtils.java

示例13: getTimeInterval

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
/**
 * 返回距离现在的时间间隔
 * 时间格式:yyyy-MM-ddTHH:mm:ss.SSSZ
 * @param formatTime
 * @return
 */
public static String getTimeInterval(String formatTime) {
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
    simpleDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss.SSS");
    String time = formatTime.replace("T", " ").replace("Z", "");
    Date date = null;
    try {
        date = simpleDateFormat.parse(time);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    long seconds = (System.currentTimeMillis() - date.getTime()) / 1000;
    if (seconds < 60) {
        return "刚刚";
    }
    seconds /= 60;
    if (seconds < 60) {
        return seconds + "分钟前";
    }
    seconds /= 60;
    if (seconds < 24) {
        return seconds + "小时前";
    }
    seconds /= 24;
    if (seconds < 30) {
        return seconds + "小时前";
    }
    seconds /= 30;
    if (seconds < 12) {
        return seconds + "月前";
    }
    seconds /= 12;
    return seconds + "年前";
}
 
开发者ID:1014277960,项目名称:DailyReader,代码行数:40,代码来源:TimeUtil.java

示例14: preprocessText

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
private String[] preprocessText() {
    String[] text;
    if (this.text == null || this.text.length == 0 || (this.text.length == 1 && TextUtils.isEmpty(this.text[0]) == true)) {
        text = defaultText;
    } else {
        text = new String[this.text.length];
        for (int i = 0; i < text.length; i++) {
            text[i] = new String(this.text[i] != null ? this.text[i] : "");

            Date date = Calendar.getInstance().getTime();
            SimpleDateFormat sdf = new SimpleDateFormat();
            for (int j = 0; j < DATE_REPLACEMENTS.length; j++) {
                while (text[i].indexOf(DATE_REPLACEMENTS[j]) >= 0) {
                    sdf.applyPattern(DATE_FORMAT[j]);
                    text[i] = text[i].replace(DATE_REPLACEMENTS[j], sdf.format(date));
                }
            }
        }
    }

    if (text == null) {
        if (defaultText == null) {
            text = new String[]{""};
        } else {
            text = defaultText;
        }
    }

    return text;
}
 
开发者ID:monthlypub,项目名称:SmingZZick_App,代码行数:31,代码来源:TextMakingInfo.java

示例15: getPartString

import java.text.SimpleDateFormat; //导入方法依赖的package包/类
public String getPartString(Session session, Object dateTime, int part) {

        String javaPattern = "";

        switch (part) {

            case DAY_NAME :
                javaPattern = "EEEE";
                break;

            case MONTH_NAME :
                javaPattern = "MMMM";
                break;
        }

        SimpleDateFormat format = session.getSimpleDateFormatGMT();

        try {
            format.applyPattern(javaPattern);
        } catch (Exception e) {}

        Date date = (Date) convertSQLToJavaGMT(session, dateTime);

        return format.format(date);
    }
 
开发者ID:tiweGH,项目名称:OpenDiabetes,代码行数:26,代码来源:DateTimeType.java


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