當前位置: 首頁>>代碼示例>>Java>>正文


Java JSON.DEFFAULT_DATE_FORMAT屬性代碼示例

本文整理匯總了Java中com.alibaba.fastjson.JSON.DEFFAULT_DATE_FORMAT屬性的典型用法代碼示例。如果您正苦於以下問題:Java JSON.DEFFAULT_DATE_FORMAT屬性的具體用法?Java JSON.DEFFAULT_DATE_FORMAT怎麽用?Java JSON.DEFFAULT_DATE_FORMAT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在com.alibaba.fastjson.JSON的用法示例。


在下文中一共展示了JSON.DEFFAULT_DATE_FORMAT屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: write

public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
                  int features) throws IOException {
    SerializeWriter out = serializer.out;
    if (object == null) {
        out.writeNull();
    } else {
        if (fieldType == null) {
            fieldType = object.getClass();
        }

        if (fieldType == LocalDateTime.class) {
            final int mask = SerializerFeature.UseISO8601DateFormat.getMask();
            LocalDateTime dateTime = (LocalDateTime) object;
            String format = serializer.getDateFormatPattern();

            if (format == null && (features & mask) != 0 || serializer.isEnabled(SerializerFeature.UseISO8601DateFormat)) {
                format = formatter_iso8601_pattern;
            }

            if (dateTime.getNano() == 0 || format != null) {

                if (format == null) {
                    format = JSON.DEFFAULT_DATE_FORMAT;
                }
                write(out, dateTime, format);
            } else if (out.isEnabled(SerializerFeature.WriteDateUseDateFormat)) {
                //使用固定格式轉化時間
                write(out, dateTime, JSON.DEFFAULT_DATE_FORMAT);
            } else {
                out.writeLong(dateTime.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli());
            }
        } else {
            out.writeString(object.toString());
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:Jdk8DateCodec.java

示例2: test_castToDate

public void test_castToDate() throws Exception {
    JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
    Date date = TypeUtils.castToDate("2012-07-15 12:12:11");
    
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    format.setTimeZone(JSON.defaultTimeZone);
    Assert.assertEquals(format.parseObject("2012-07-15 12:12:11"), date);
    JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:TypeUtilsTest_castToDate.java

示例3: test_for_issue_1

public void test_for_issue_1() throws Exception {
    JSON.DEFFAULT_DATE_FORMAT = "yyyyMMddHHmmssSSSZ";

    String json = "{\"value\":\"20180131022733000-0800\"}";
    JSONObject object = JSON.parseObject(json);
    object.getObject("value", Date.class);

    JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:Issue_for_zuojian.java

示例4: test_0

public void test_0 () throws Exception {
    long millis = (System.currentTimeMillis() / 1000) * 1000;
    
    SimpleDateFormat format = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, JSON.defaultLocale);
    format.setTimeZone(JSON.defaultTimeZone);
    String text = "\"" + format.format(new Date(millis)) + "\"";
    System.out.println(text);
    Assert.assertEquals(new Timestamp(millis), JSON.parseObject("" + millis, Timestamp.class));
    Assert.assertEquals(new Timestamp(millis), JSON.parseObject("\"" + millis + "\"", Timestamp.class));
    Assert.assertEquals(new Timestamp(millis), JSON.parseObject(text, Timestamp.class));
    Assert.assertEquals(new java.sql.Date(millis), JSON.parseObject(text, java.sql.Date.class));
    Assert.assertEquals(new java.util.Date(millis), JSON.parseObject(text, java.util.Date.class));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:TimestampTest.java

示例5: test_for_xiayucai2012

public void test_for_xiayucai2012() throws Exception {
    String text = "{\"date\":\"0000-00-00 00:00:00\"}";
    JSONObject json = JSON.parseObject(text);
    Date date = json.getObject("date", Date.class);
    
    SimpleDateFormat dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, JSON.defaultLocale);
    dateFormat.setTimeZone(JSON.defaultTimeZone);
    
    Assert.assertEquals(dateFormat.parse(json.getString("date")), date);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:10,代碼來源:Bug_for_xiayucai2012.java

示例6: DefaultJSONParser

public DefaultJSONParser(Object input, JSONLexer lexer, ParserConfig config) {
    this.dateFormatPattern = JSON.DEFFAULT_DATE_FORMAT;
    this.contextArray = new ParseContext[8];
    this.contextArrayIndex = 0;
    this.resolveStatus = 0;
    this.extraTypeProviders = null;
    this.extraProcessors = null;
    this.lexer = lexer;
    this.input = input;
    this.config = config;
    this.symbolTable = config.getSymbolTable();
    lexer.nextToken(12);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:13,代碼來源:DefaultJSONParser.java

示例7: test_for_issue

public void test_for_issue() throws Exception {
    JSON.DEFFAULT_DATE_FORMAT = "yyyyMMddHHmmssSSSZ";
    String json = "{\"value\":\"20180131022733000-0800\"}";
    JSON.parseObject(json, Model.class);
    JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:6,代碼來源:Issue_for_zuojian.java

示例8: serializer

@Override
public <T> byte[] serializer(T obj) {
	JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	return JSON.toJSONBytes(obj, SerializerFeature.WriteDateUseDateFormat);
}
 
開發者ID:yanghuijava,項目名稱:elephant,代碼行數:5,代碼來源:JsonSerializer.java

示例9: castToDate

public static final Date castToDate(Object value) {
    if (value == null) {
        return null;
    }
    if (value instanceof Calendar) {
        return ((Calendar) value).getTime();
    }
    if (value instanceof Date) {
        return (Date) value;
    }
    long j = -1;
    if (value instanceof Number) {
        j = ((Number) value).longValue();
    }
    if (value instanceof String) {
        String strVal = (String) value;
        if (strVal.indexOf(45) != -1) {
            String format;
            if (strVal.length() == JSON.DEFFAULT_DATE_FORMAT.length()) {
                format = JSON.DEFFAULT_DATE_FORMAT;
            } else if (strVal.length() == 10) {
                format = "yyyy-MM-dd";
            } else if (strVal.length() == "yyyy-MM-dd HH:mm:ss".length()) {
                format = "yyyy-MM-dd HH:mm:ss";
            } else {
                format = "yyyy-MM-dd HH:mm:ss.SSS";
            }
            try {
                return new SimpleDateFormat(format).parse(strVal);
            } catch (ParseException e) {
                throw new JSONException("can not cast to Date, value : " + strVal);
            }
        } else if (strVal.length() == 0) {
            return null;
        } else {
            j = Long.parseLong(strVal);
        }
    }
    if (j >= 0) {
        return new Date(j);
    }
    throw new JSONException("can not cast to Date, value : " + value);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:43,代碼來源:TypeUtils.java

示例10: castToDate

public static final Date castToDate(Object value) {
    if (value == null) {
        return null;
    }

    if (value instanceof Calendar) {
        return ((Calendar) value).getTime();
    }

    if (value instanceof Date) {
        return (Date) value;
    }

    long longValue = -1;

    if (value instanceof Number) {
        longValue = ((Number) value).longValue();
        return new Date(longValue);
    }

    if (value instanceof String) {
        String strVal = (String) value;

        if (strVal.indexOf('-') != -1) {
            String format;
            if (strVal.length() == JSON.DEFFAULT_DATE_FORMAT.length()) {
                format = JSON.DEFFAULT_DATE_FORMAT;
            } else if (strVal.length() == 10) {
                format = "yyyy-MM-dd";
            } else if (strVal.length() == "yyyy-MM-dd HH:mm:ss".length()) {
                format = "yyyy-MM-dd HH:mm:ss";
            } else {
                format = "yyyy-MM-dd HH:mm:ss.SSS";
            }

            SimpleDateFormat dateFormat = new SimpleDateFormat(format);
            try {
                return (Date) dateFormat.parse(strVal);
            } catch (ParseException e) {
                throw new JSONException("can not cast to Date, value : " + strVal);
            }
        }

        if (strVal.length() == 0) {
            return null;
        }

        longValue = Long.parseLong(strVal);
    }

    if (longValue < 0) {
        throw new JSONException("can not cast to Date, value : " + value);
    }

    return new Date(longValue);
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:56,代碼來源:TypeUtils.java


注:本文中的com.alibaba.fastjson.JSON.DEFFAULT_DATE_FORMAT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。