本文整理汇总了Java中org.joda.time.format.ISOPeriodFormat.standard方法的典型用法代码示例。如果您正苦于以下问题:Java ISOPeriodFormat.standard方法的具体用法?Java ISOPeriodFormat.standard怎么用?Java ISOPeriodFormat.standard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.format.ISOPeriodFormat
的用法示例。
在下文中一共展示了ISOPeriodFormat.standard方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertTime
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
private int convertTime(String time) {
PeriodFormatter formatter = ISOPeriodFormat.standard();
Period p = formatter.parsePeriod(time);
Seconds s = p.toStandardSeconds();
return s.getSeconds();
}
示例2: serialize
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
@Override
public void serialize(
final Duration duration,
final JsonGenerator jgen,
final SerializerProvider provider) throws IOException, JsonProcessingException
{
if (duration == null)
{
jgen.writeNull();
return;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
jgen.writeString(duration.toPeriod().toString(formatter));
}
示例3: deserialize
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
@Override
public Duration deserialize(final JsonParser parser, final DeserializationContext ctxt)
throws JsonParseException, IOException
{
final JsonToken jsonToken = parser.getCurrentToken();
if (jsonToken == JsonToken.VALUE_NUMBER_INT)
{
return new Duration(parser.getLongValue());
}
else if (jsonToken == JsonToken.VALUE_STRING)
{
final String str = parser.getText().trim();
if (str.length() == 0)
{
return null;
}
final PeriodFormatter formatter = ISOPeriodFormat.standard();
return formatter.parsePeriod(str).toStandardDuration();
}
throw ctxt.mappingException(Duration.class);
}
示例4: setInto
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
/**
* Extracts duration values from an object of this converter's type, and
* sets them into the given ReadWritableDuration.
*
* @param period period to get modified
* @param object the String to convert, must not be null
* @param chrono the chronology to use
* @return the millisecond duration
* @throws ClassCastException if the object is invalid
*/
public void setInto(ReadWritablePeriod period, Object object, Chronology chrono) {
String str = (String) object;
PeriodFormatter parser = ISOPeriodFormat.standard();
period.clear();
int pos = parser.parseInto(period, str, 0);
if (pos < str.length()) {
if (pos < 0) {
// Parse again to get a better exception thrown.
parser.withParseType(period.getPeriodType()).parseMutablePeriod(str);
}
throw new IllegalArgumentException("Invalid format: \"" + str + '"');
}
}
示例5: setUp
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
@Before
public void setUp() {
formatter = ISOPeriodFormat.standard();
processor1 = new ParsePeriod();
processor2 = new ParsePeriod(formatter);
processorChain1 = new ParsePeriod(new IdentityTransform());
processorChain2 = new ParsePeriod(formatter, new IdentityTransform());
processors = Arrays.asList(processor1, processor2, processorChain1,
processorChain2);
}
示例6: setUp
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
@Before
public void setUp() {
formatter = ISOPeriodFormat.standard();
processor1 = new FmtPeriod();
processor2 = new FmtPeriod(formatter);
processorChain1 = new FmtPeriod(new IdentityTransform());
processorChain2 = new FmtPeriod(formatter, new IdentityTransform());
processors = Arrays.asList(processor1, processor2, processorChain1,
processorChain2);
}
示例7: GetVideoLength
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
public int[] GetVideoLength(String id) {
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Start id=" + id);
}
JSONObject j = GetData(request_type.GET, "https://www.googleapis.com/youtube/v3/videos?id=" + id + "&key=" + apikey + "&part=contentDetails");
if (j.getBoolean("_success")) {
if (j.getInt("_http") == 200) {
JSONArray a = j.getJSONArray("items");
if (a.length() > 0) {
JSONObject i = a.getJSONObject(0);
JSONObject cd = i.getJSONObject("contentDetails");
PeriodFormatter formatter = ISOPeriodFormat.standard();
Period d = formatter.parsePeriod(cd.getString("duration"));
//String d = cd.getString("duration").substring(2);
int h, m, s;
String hours = d.toStandardHours().toString().substring(2);
h = Integer.parseInt(hours.substring(0, hours.indexOf("H")));
String minutes = d.toStandardMinutes().toString().substring(2);
m = Integer.parseInt(minutes.substring(0, minutes.indexOf("M")));
String seconds = d.toStandardSeconds().toString().substring(2);
s = Integer.parseInt(seconds.substring(0, seconds.indexOf("S")));
/*
* if (d.contains("H")) { h =
* Integer.parseInt(d.substring(0, d.indexOf("H")));
*
* d = d.substring(0, d.indexOf("H")); }
*
* if (d.contains("M")) { m =
* Integer.parseInt(d.substring(0, d.indexOf("M")));
*
* d = d.substring(0, d.indexOf("M")); }
*
* s = Integer.parseInt(d.substring(0, d.indexOf("S")));
*/
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Success");
}
return new int[]{
h, m, s
};
} else {
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail");
}
return new int[]{
0, 0, 0
};
}
} else {
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail2");
}
return new int[]{
0, 0, 0
};
}
}
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println(">>>[DEBUG] YouTubeAPIv3.GetVideoLength Fail3");
}
return new int[]{
0, 0, 0
};
}
示例8: processingDetailedResults
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
/**
*
* @param response
* gets the detailed informations JSON produced eariler,
* containing all informations about a sinlge video
* @param youtubeTemp
* is a reference to the youtube object we try to fill in the for
* loop
*
* the method iterates over the details JSON and fills all fields
* @throws java.text.ParseException
*/
private YoutubeMetaData processingDetailedResults(JSONObject response,
YoutubeMetaData youtubeTemp) {
JSONArray responseItems = (JSONArray) response.get("items");
JSONObject responseItemsEntry = (JSONObject) responseItems.get(0);
JSONObject responseSnippet = (JSONObject) responseItemsEntry
.get("snippet");
JSONObject responseStatus = (JSONObject) responseItemsEntry
.get("status");
System.out.println("channelId "
+ responseSnippet.get("channelId").toString());
youtubeTemp.setChannelID(responseSnippet.get("channelId").toString());
youtubeTemp.setTitle(responseSnippet.get("title").toString());
System.out.println("title: " + responseSnippet.get("title").toString());
String tempDate = responseSnippet.get("publishedAt").toString();
DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd'T'HH:mm:ss");
Date date = null;
try {
date = formatter.parse(tempDate);
} catch (java.text.ParseException e) {
e.printStackTrace();
return null;
}
youtubeTemp.setPublishedAt(date);
System.out.println("publishedAt: " + youtubeTemp.getPublishedAt());
JSONObject responseContentDetails = (JSONObject) responseItemsEntry
.get("contentDetails");
youtubeTemp.setDuration(responseContentDetails.get("duration")
.toString());
PeriodFormatter pf = ISOPeriodFormat.standard();
Period p = pf.parsePeriod(responseContentDetails.get("duration")
.toString());
Seconds s = p.toStandardSeconds();
System.out.println("durationInSecond: " + s.getSeconds());
youtubeTemp.setDurationInSeconds(s.getSeconds());
System.out.println("duration "
+ responseContentDetails.get("duration").toString());
JSONObject responseStatistics = (JSONObject) responseItemsEntry
.get("statistics");
youtubeTemp
.setViewCount(responseStatistics.get("viewCount").toString());
System.out.println("viewCount"
+ responseStatistics.get("viewCount").toString());
youtubeTemp
.setLikeCount(responseStatistics.get("likeCount").toString());
System.out.println("likeCount"
+ responseStatistics.get("likeCount").toString());
youtubeTemp.setDislikeCount(responseStatistics.get("dislikeCount")
.toString());
System.out.println("dislikeCount"
+ responseStatistics.get("dislikeCount").toString());
youtubeTemp.setCommentCount(responseStatistics.get("commentCount")
.toString());
System.out.println("commentCount"
+ responseStatistics.get("commentCount").toString());
boolean isCreativeCommon = false;
if (responseStatus.get("license").toString() == "creativeCommon")
isCreativeCommon = true;
youtubeTemp.setCreativeCommon(isCreativeCommon);
System.out.println("creativeCommon: " + youtubeTemp.isCreativeCommon());
System.out.println("------------------------------");
return youtubeTemp;
}
示例9: serialize
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
/**
* Gson invokes this call-back method during serialization when it encounters a field of the
* specified type. <p>
*
* In the implementation of this call-back method, you should consider invoking
* {@link JsonSerializationContext#serialize(Object, Type)} method to create JsonElements for any
* non-trivial field of the {@code src} object. However, you should never invoke it on the
* {@code src} object itself since that will cause an infinite loop (Gson will call your
* call-back method again).
* @param src the object that needs to be converted to Json.
* @param typeOfSrc the actual type (fully genericized version) of the source object.
* @return a JsonElement corresponding to the specified object.
*/
@Override
public JsonElement serialize(Period src, Type typeOfSrc, JsonSerializationContext context)
{
final PeriodFormatter fmt = ISOPeriodFormat.standard();
return new JsonPrimitive(fmt.print(src));
}
示例10: deserialize
import org.joda.time.format.ISOPeriodFormat; //导入方法依赖的package包/类
/**
* Gson invokes this call-back method during deserialization when it encounters a field of the
* specified type. <p>
*
* In the implementation of this call-back method, you should consider invoking
* {@link JsonDeserializationContext#deserialize(JsonElement, Type)} method to create objects
* for any non-trivial field of the returned object. However, you should never invoke it on the
* the same type passing {@code json} since that will cause an infinite loop (Gson will call your
* call-back method again).
* @param json The Json data being deserialized
* @param typeOfT The type of the Object to deserialize to
* @return a deserialized object of the specified type typeOfT which is a subclass of {@code T}
* @throws JsonParseException if json is not in the expected format of {@code typeOfT}
*/
@Override
public Period deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException
{
// Do not try to deserialize null or empty values
if (json.getAsString() == null || json.getAsString().isEmpty())
{
return null;
}
final PeriodFormatter fmt = ISOPeriodFormat.standard();
return fmt.parsePeriod(json.getAsString());
}