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