本文整理汇总了Java中com.alibaba.fastjson.serializer.JSONSerializer.setDateFormat方法的典型用法代码示例。如果您正苦于以下问题:Java JSONSerializer.setDateFormat方法的具体用法?Java JSONSerializer.setDateFormat怎么用?Java JSONSerializer.setDateFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.serializer.JSONSerializer
的用法示例。
在下文中一共展示了JSONSerializer.setDateFormat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_0
import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_0() throws Exception {
JSONSerializer serializer = new JSONSerializer();
serializer.setDateFormat("yyyy");
Assert.assertEquals("yyyy", ((SimpleDateFormat) serializer.getDateFormat()).toPattern());
Assert.assertEquals("yyyy", serializer.getDateFormatPattern());
serializer.setDateFormat("yyyy-MM");
Assert.assertEquals("yyyy-MM", ((SimpleDateFormat) serializer.getDateFormat()).toPattern());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(JSON.defaultTimeZone);
serializer.setDateFormat(format);
Assert.assertEquals("yyyy-MM-dd", serializer.getDateFormatPattern());
serializer.close();
}
示例2: toJSONStringWithDateFormat
import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public static final String toJSONStringWithDateFormat(Object object, String dateFormat, SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
for (SerializerFeature feature : features) {
serializer.config(feature, true);
}
serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
if (dateFormat != null) {
serializer.setDateFormat(dateFormat);
}
serializer.write(object);
String serializeWriter = out.toString();
return serializeWriter;
} finally {
out.close();
}
}
示例3: toJSONStringWithDateFormat
import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
/**
* @since 1.1.14
*/
public static final String toJSONStringWithDateFormat(Object object, String dateFormat,
SerializerFeature... features) {
SerializeWriter out = new SerializeWriter();
try {
JSONSerializer serializer = new JSONSerializer(out);
for (SerializerFeature feature : features) {
serializer.config(feature, true);
}
serializer.config(SerializerFeature.WriteDateUseDateFormat, true);
if (dateFormat != null) {
serializer.setDateFormat(dateFormat);
}
serializer.write(object);
return out.toString();
} finally {
out.close();
}
}
示例4: test_
import com.alibaba.fastjson.serializer.JSONSerializer; //导入方法依赖的package包/类
public void test_() throws Exception {
JSONSerializer ser = new JSONSerializer(new SerializeConfig());
ser.setDateFormat(new ISO8601DateFormat());
Assert.assertEquals(null, ser.getDateFormatPattern());
ser.close();
}