Android Open Source - VideoExtand Date Util






From Project

Back to project page VideoExtand.

License

The source code is released under:

Apache License

If you think the Android project VideoExtand listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2014 The Android Open Source Project
 *//w  w  w  .  j av a  2  s  . c  o  m
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Auther?yinglovezhuzhu@gmail.com
 * File: DateUtil.java
 * Date?2014?1?2?
 * Version?v1.0
 */  
package com.yuninfo.videoextand.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * ???????????
 * @author yinglovezhuzhu@gmail.com
 */
public class DateUtil {
  private DateUtil() {}
  
  /**
   * ???????????
   * @param pattern ?????
   * @return
   */
  public static String getSystemDate(String pattern) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.getDefault());
    return dateFormat.format(new Date(System.currentTimeMillis()));
  }
  
  /**
   * ?????????
   * @return ????
   */
  public static int getYear() {
    Calendar c = Calendar.getInstance(Locale.getDefault());
    return c.get(Calendar.YEAR);
  }
  
  /**
   * ?????
   * @param timeSecond ????????
   * @return
   */
  public static int getDay(long milliseconds) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("d", Locale.getDefault());
    String day = dateFormat.format(new Date(milliseconds));
    try {
      return Integer.valueOf(day);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return 0;
  }
  
  /**
   * The seconds1 is the same day with seconds2.(????)
   * @param seconds1
   * @param seconds2
   * @return
   */
  public static boolean isSameDay(long seconds1, long seconds2) {
    return Math.abs(seconds1 - seconds2) < 86400;
  }
  
  /**
   * ??????????????????
   * @param backStep ???????????
   * @param minYear ?????????????????????????????????????
   * @return
   */
  public static List<Integer> getYears(int backStep, int minYear) {
    List<Integer> years = new ArrayList<Integer>();
    int year = getYear();
    for (int i = 0; i < backStep; i++) {
      if(year - i < minYear) {
        break;
      }
      years.add(year - i);
    }
    return years;
  }
  
  /**
   * ????????
   * @param pattern
   * @return
   */
  public static String getYesterdayDate(String pattern) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.getDefault());
    Calendar calendar = Calendar.getInstance(Locale.getDefault());
    calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 1);
    return dateFormat.format(calendar.getTime());
  }
  
  /**
   * ???????????srcPattern?????????distPattern
   * ????????????????????????????????????????????????????????????????????????????
   * ???????????????????????????????????????????????????????????????????????????
   * ?????????????????????????
   * @param source
   * @param srcPattern
   * @param distPattern
   * @return ?????????????????????????????????????????
   */
  public static String changeFormat(String source, String srcPattern, String distPattern) {
    SimpleDateFormat srcFormt = new SimpleDateFormat(srcPattern, Locale.getDefault());
    SimpleDateFormat distFormt = new SimpleDateFormat(distPattern, Locale.getDefault());
    try {
      return distFormt.format(srcFormt.parse(source));
    } catch (ParseException e) {
      e.printStackTrace();
      return source;
    }
  }
  
  /**
   * Format date.
   * @param pattern
   * @param milliseconds
   * @return
   */
  public static String format(String pattern, long milliseconds) {
    SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.getDefault());
    try {
      return dateFormat.format(new Date(milliseconds));
    } catch (Exception e) {
      e.printStackTrace();
    }
    return "";
  }
}




Java Source Code List

com.example.androidtest.MainActivity.java
com.yuninfo.videoextand.BaseActivity.java
com.yuninfo.videoextand.Config.java
com.yuninfo.videoextand.ReadCardActivity.java
com.yuninfo.videoextand.SendCardActivity.java
com.yuninfo.videoextand.bean.CommonReq.java
com.yuninfo.videoextand.bean.ReadVideoResp.java
com.yuninfo.videoextand.bean.SendVideoResp.java
com.yuninfo.videoextand.bean.UploadReq.java
com.yuninfo.videoextand.bean.UploadResp.java
com.yuninfo.videoextand.player.VideoPlayerActivity.java
com.yuninfo.videoextand.recorder.RecorderActivity.java
com.yuninfo.videoextand.uploader.ProgressListener.java
com.yuninfo.videoextand.uploader.ProgressMultipartEntity.java
com.yuninfo.videoextand.uploader.ProgressOutputStream.java
com.yuninfo.videoextand.uploader.UploadHandler.java
com.yuninfo.videoextand.uploader.UploadThread.java
com.yuninfo.videoextand.utils.BeanRefUtil.java
com.yuninfo.videoextand.utils.DateUtil.java
com.yuninfo.videoextand.utils.FileUtil.java
com.yuninfo.videoextand.utils.HttpUtil.java
com.yuninfo.videoextand.utils.LogUtil.java
com.yuninfo.videoextand.utils.StringUtil.java
com.yuninfo.videoextand.widget.CustomPopupWindow.java
com.yuninfo.videoextand.widget.TitleBar.java
com.yuninfo.videoextand.widget.dialog.MenuDialog.java