本文整理汇总了Java中freemarker.template.SimpleDate类的典型用法代码示例。如果您正苦于以下问题:Java SimpleDate类的具体用法?Java SimpleDate怎么用?Java SimpleDate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleDate类属于freemarker.template包,在下文中一共展示了SimpleDate类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exec
import freemarker.template.SimpleDate; //导入依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException {
testAtLeastOneArgument(arguments);
String value = readValue(arguments.get(0));
MessageFormat formatter = new MessageFormat(value, bundle.getLocale());
if (arguments.size() == 1) {
value = formatter.format(new Object[] {});
} else {
List<Object> parameters = new ArrayList<>();
for (Object obj : arguments.subList(1, arguments.size())) {
if (obj instanceof SimpleNumber) {
parameters.add(((SimpleNumber) obj).getAsNumber());
} else if (obj instanceof SimpleDate) {
parameters.add(((SimpleDate) obj).getAsDate());
} else {
parameters.add(obj.toString());
}
}
value = formatter.format(parameters.toArray(), new StringBuffer(), null).toString();
}
return value;
}
示例2: exec
import freemarker.template.SimpleDate; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
public TemplateModel exec(List args) {
long sum = 0;
for (Object arg : args) {
arg = LiteralParser.parse((String) arg);
if (arg instanceof Date)
sum += ((Date) arg).getTime();
else if (arg instanceof Timestamp)
sum += ((Timestamp) arg).getTime();
else if (arg instanceof Number)
sum += ((Number) arg).longValue();
else if (arg != null)
throw new IllegalArgumentException("Not a supported date type: " + arg.getClass());
}
return new SimpleDate(new java.sql.Date(sum));
}
示例3: getDate
import freemarker.template.SimpleDate; //导入依赖的package包/类
public static Date getDate(Map params, String paramName){
SimpleDate valueModel=(SimpleDate)params.get(paramName);
if (valueModel!=null){
Date value=valueModel.getAsDate();
return value;
}
return null;
}
示例4: testParamTranslation
import freemarker.template.SimpleDate; //导入依赖的package包/类
@Test
public void testParamTranslation() throws TemplateModelException, ParseException {
ResourceBundle bundle = new SimpleBundle("foo", "bar {0} {1} {2}");
FreemarkerMessageMethod method = new FreemarkerMessageMethod(bundle);
SimpleNumber simpleNumber = new SimpleNumber(1234567);
Date date = new Date(new SimpleDateFormat("yyyy-MM-dd hh:mm").parse("2014-03-14 13:11").getTime());
SimpleDate simpleDate = new SimpleDate(date);
assertEquals("bar baz 1,234,567 3/14/14 1:11 PM", method.exec(Arrays.asList("foo", "baz", simpleNumber, simpleDate)));
}
示例5: getFormattableObject
import freemarker.template.SimpleDate; //导入依赖的package包/类
private Date getFormattableObject(Object value) {
if (value instanceof SimpleDate) {
return ((SimpleDate) value).getAsDate();
} else {
throw new PippoRuntimeException("Formattable object for FormatTime not found!");
}
}
示例6: getFormattableObject
import freemarker.template.SimpleDate; //导入依赖的package包/类
private Date getFormattableObject(Object value) {
if (value instanceof SimpleDate) {
return ((SimpleDate) value).getAsDate();
} else {
throw new PippoRuntimeException("Formattable object for PrettyTime not found!");
}
}
示例7: wrap
import freemarker.template.SimpleDate; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
if (obj == null) {
return super.wrap(null);
}
if (obj instanceof TemplateModel) {
return (TemplateModel) obj;
}
if (obj instanceof String) {
return new SimpleScalar((String) obj);
}
if (obj instanceof Number) {
return new SimpleNumber((Number) obj);
}
if (obj instanceof java.util.Date) {
if(obj instanceof java.sql.Date) {
return new SimpleDate((java.sql.Date) obj);
}
if(obj instanceof java.sql.Time) {
return new SimpleDate((java.sql.Time) obj);
}
if(obj instanceof java.sql.Timestamp) {
return new SimpleDate((java.sql.Timestamp) obj);
}
return new SimpleDate((java.util.Date) obj, getDefaultDateType());
}
if (obj.getClass().isArray()) {
obj = convertArray(obj);
}
if (obj instanceof Collection) {
return new SimpleSequence((Collection) obj, this);
}
if (obj instanceof Boolean) {
return obj.equals(Boolean.TRUE) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE;
}
if (obj instanceof Iterator) {
return new SimpleCollection((Iterator) obj, this);
}
return handleUnknownType(obj);
}
示例8: exec
import freemarker.template.SimpleDate; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
public TemplateModel exec(List args) {
return new SimpleDate(new Date(System.currentTimeMillis()));
}