Search in sources :

Example 61 with SimpleDateFormat

use of java.text.SimpleDateFormat in project tray by grandcentrix.

the class TrayItemTest method testToString.

public void testToString() throws Exception {
    SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss dd.MM.yyyy", Locale.US);
    final Date created = new Date();
    final Date updated = new Date();
    final TrayItem item = new TrayItem("module", "key", "migratedKey", "value", created, updated);
    final String string = item.toString();
    assertTrue(string.contains(item.key()));
    assertTrue(string.contains(item.value()));
    assertTrue(string.contains(item.migratedKey()));
    assertTrue(string.contains(item.module()));
    assertTrue(string.contains(sf.format(item.updateTime())));
    assertTrue(string.contains(sf.format(item.created())));
}
Also used : TrayItem(net.grandcentrix.tray.core.TrayItem) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 62 with SimpleDateFormat

use of java.text.SimpleDateFormat in project groovy-core by groovy.

the class DateGroovyMethods method format.

/**
     * <p>Create a String representation of this date according to the given
     * format pattern and timezone.
     * <p>
     * <p>For example:
     * <code>
     * def d = new Date(0)
     * def tz = TimeZone.getTimeZone('GMT')
     * println d.format('dd/MMM/yyyy', tz)
     * </code> would return the string
     * <code>"01/Jan/1970"</code>. See documentation for {@link java.text.SimpleDateFormat}
     * for format pattern use.
     * <p>
     * <p>Note that a new DateFormat instance is created for every
     * invocation of this method (for thread safety).
     *
     * @param self   a Date
     * @param format the format pattern to use according to {@link java.text.SimpleDateFormat}
     * @param tz     the TimeZone to use
     * @return a string representation of this date.
     * @see java.text.SimpleDateFormat
     * @since 1.8.3
     */
public static String format(Date self, String format, TimeZone tz) {
    SimpleDateFormat sdf = new SimpleDateFormat(format);
    sdf.setTimeZone(tz);
    return sdf.format(self);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat)

Example 63 with SimpleDateFormat

use of java.text.SimpleDateFormat in project groovy-core by groovy.

the class InvokeMethodTest method testSetLenientOnDateFormat.

public void testSetLenientOnDateFormat() throws Throwable {
    SimpleDateFormat a = new SimpleDateFormat("MM/dd/yyyy");
    Object value = invoke(a, "setLenient", new Object[] { Boolean.FALSE });
    assertEquals("void method", null, value);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat)

Example 64 with SimpleDateFormat

use of java.text.SimpleDateFormat in project translationstudio8 by heartsome.

the class DateUtilsBasic method getFirstDayOfMonth.

/**
	 * 获取日期所在月的第一天(该类中的 getMonthBegin 也是同样的意义).
	 * @param str
	 * 				日期字符串,以 yyyy-MM-dd 格式
	 * @return String 
	 * 				以 yyyy-MM-dd 格式, 如果传入参数为 null 或者解析字符串时发生异常,返回空串""
	 * @see DateUtilsBasic#getMonthBegin(String)
	 */
public static String getFirstDayOfMonth(String str) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    Calendar calendar = Calendar.getInstance();
    try {
        Date date = format.parse(str);
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        return format.format(calendar.getTime());
    } catch (Exception e) {
        if (Constants.DEBUG) {
            e.printStackTrace();
        }
        return "";
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParseException(java.text.ParseException)

Example 65 with SimpleDateFormat

use of java.text.SimpleDateFormat in project translationstudio8 by heartsome.

the class DateUtilsBasic method getSaterdayOfWeek.

/**
	 * 得到指定日期的星期六.
	 * @param date
	 *            	日期字符串,以 yyyy-MM-dd 格式
	 * @return String 
	 * 				以 yyyy-MM-dd 格式,星期六是该周的最后一天, 如果传入参数为 null 或者解析字符串时发生异常,返回空串""
	 */
public static String getSaterdayOfWeek(String date) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    try {
        Date datePoint = dateFormat.parse(date);
        Calendar c = Calendar.getInstance();
        c.setTime(datePoint);
        int dayofweek = c.get(Calendar.DAY_OF_WEEK) - 1;
        c.add(Calendar.DATE, -dayofweek + 6);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return sdf.format(c.getTime());
    } catch (Exception e) {
        if (Constants.DEBUG) {
            e.printStackTrace();
        }
        return "";
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ParseException(java.text.ParseException)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)3363 Date (java.util.Date)1843 ParseException (java.text.ParseException)559 DateFormat (java.text.DateFormat)526 Test (org.junit.Test)399 Calendar (java.util.Calendar)341 ArrayList (java.util.ArrayList)317 File (java.io.File)253 IOException (java.io.IOException)223 GregorianCalendar (java.util.GregorianCalendar)143 HashMap (java.util.HashMap)132 Locale (java.util.Locale)82 Map (java.util.Map)74 TimeZone (java.util.TimeZone)67 DateField (edu.uci.ics.textdb.api.field.DateField)64 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 List (java.util.List)64 StringField (edu.uci.ics.textdb.api.field.StringField)63