本文整理匯總了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();
}