Android Open Source - Mamytas Date Helper






From Project

Back to project page Mamytas.

License

The source code is released under:

GNU General Public License

If you think the Android project Mamytas 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

package mn.aug.restfulandroid.util;
//from  w  ww  .  j av  a 2 s .  co  m
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Antoine on 16/11/2014.
 */
public class DateHelper {
    public static SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd-MM-yyyy  HH:mm");
    public static SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    public static SimpleDateFormat dateTimeFormatUS = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    public static SimpleDateFormat dateFormatUS = new SimpleDateFormat("yyyy-MM-dd");
    public static SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");

    /**
     *
     * @param yourFormat String vous passez le format que vous voulez "yyyy-MM-dd HH:mm" par exemple
     * @param yourDate en thorie  votre format ex: "2014-12-25"
     * @return String votre date  votre format
     * @throws ParseException Si jamais votre format ou votre date n'est pas bonne, bim grosse exception !
     */
    public static String getDateToYourFormat(String yourFormat, String yourDate) throws ParseException{
        SimpleDateFormat theFormat = new SimpleDateFormat(yourFormat);

        String retour = null;
        Date parsedTimeStamp = theFormat.parse(yourDate);
        retour = String.valueOf(theFormat.format(parsedTimeStamp.getTime()));
        return retour;
    }

    /**
     *
     * @param yourFormat String vous passez le format que vous voulez "yyyy-MM-dd HH:mm" par exemple
     * @param yourTime ex: 1785624688
     * @return String votre date  votre format
     * @throws ParseException Si jamais votre format ou votre date n'est pas bonne, bim grosse exception !
     */
    public static String getDateToYourFormat(String yourFormat, long yourTime) throws ParseException{
        SimpleDateFormat theFormat = new SimpleDateFormat(yourFormat);
        return theFormat.format(yourTime);
    }

    /**
     *
     * @param dateTime String au format "yyyy-MM-dd HH:mm"
     * @return String "yyyy-MM-dd"
     * @throws ParseException format attendu non respect
     */
    public static String getDateTimeFromDateTime(String dateTime) throws ParseException{
        String retour = null;
        Date parsedTimeStamp = dateTimeFormatUS.parse(dateTime);
        retour = String.valueOf(dateTimeFormatUS.format(parsedTimeStamp.getTime()));
        return retour;
    }


    /**
     *
     * @param date String au format "yyyy-MM-dd" ou mme "yyyy-MM-dd HH:mm"
     * @return String "yyyy-MM-dd"
     * @throws ParseException format attendu non respect
     */
    public static String getDateFromDate(String date) throws ParseException{
        String retour = null;
        Date parsedTimeStamp = dateFormatUS.parse(date);
        retour = String.valueOf(dateFormatUS.format(parsedTimeStamp.getTime()));
        return retour;
    }

    /**
     *
     * @param dateTime String au format "yyyy-MM-dd HH:mm"
     * @return String "yyyy-MM-dd"
     * @throws ParseException format attendu non respect
     */
    public static String getTimeFromDateTime(String dateTime) throws ParseException{
        String retour = null;
        Date parsedTimeStamp = dateTimeFormatUS.parse(dateTime);
        retour = String.valueOf(timeFormat.format(parsedTimeStamp.getTime()));
        return retour;
    }
    /**
     *
     * @param time String au format "yyyy-MM-dd HH:mm"
     * @return String "yyyy-MM-dd"
     * @throws ParseException format attendu non respect
     */
    public static String getTimeFromTime(String time) throws ParseException{
        String retour = null;
        Date parsedTimeStamp = timeFormat.parse(time);
        retour = String.valueOf(timeFormat.format(parsedTimeStamp.getTime()));
        return retour;
    }

    public static String getDateFromDate(long time) {
        return dateFormatUS.format(time);
    }






}




Java Source Code List

mn.aug.restfulandroid.activity.AboutActivity.java
mn.aug.restfulandroid.activity.LoginActivity.java
mn.aug.restfulandroid.activity.ProjectEditor.java
mn.aug.restfulandroid.activity.ProjectsActivity.java
mn.aug.restfulandroid.activity.ProjectsArrayAdapter.java
mn.aug.restfulandroid.activity.TaskActivity.java
mn.aug.restfulandroid.activity.TaskEditor.java
mn.aug.restfulandroid.activity.TasksActivity.java
mn.aug.restfulandroid.activity.TasksArrayAdapter.java
mn.aug.restfulandroid.activity.TimerServiceHelper.java
mn.aug.restfulandroid.activity.TimerService.java
mn.aug.restfulandroid.activity.TimersArrayAdapter.java
mn.aug.restfulandroid.activity.base.RESTfulActivity.java
mn.aug.restfulandroid.activity.base.RESTfulListActivity.java
mn.aug.restfulandroid.activity.base.UndoBarController.java
mn.aug.restfulandroid.provider.CommentsDBAccess.java
mn.aug.restfulandroid.provider.ListsDBAccess.java
mn.aug.restfulandroid.provider.OwnershipDBAccess.java
mn.aug.restfulandroid.provider.ProviderDbHelper.java
mn.aug.restfulandroid.provider.RemindersDBAccess.java
mn.aug.restfulandroid.provider.TasksDBAccess.java
mn.aug.restfulandroid.provider.UsersDBAccess.java
mn.aug.restfulandroid.rest.AbstractRestMethod.java
mn.aug.restfulandroid.rest.DeleteListRestMethod.java
mn.aug.restfulandroid.rest.DeleteTaskRestMethod.java
mn.aug.restfulandroid.rest.GetListsRestMethod.java
mn.aug.restfulandroid.rest.GetTasksRestMethod.java
mn.aug.restfulandroid.rest.GetTimersRestMethod.java
mn.aug.restfulandroid.rest.LoginRestMethod.java
mn.aug.restfulandroid.rest.PostListRestMethod.java
mn.aug.restfulandroid.rest.PostTaskRestMethod.java
mn.aug.restfulandroid.rest.PostTimerRestMethod.java
mn.aug.restfulandroid.rest.PutListRestMethod.java
mn.aug.restfulandroid.rest.PutTaskRestMethod.java
mn.aug.restfulandroid.rest.PutTimerRestMethod.java
mn.aug.restfulandroid.rest.Request.java
mn.aug.restfulandroid.rest.Response.java
mn.aug.restfulandroid.rest.RestClient.java
mn.aug.restfulandroid.rest.RestMethodFactory.java
mn.aug.restfulandroid.rest.RestMethodResult.java
mn.aug.restfulandroid.rest.RestMethod.java
mn.aug.restfulandroid.rest.ShareListRestMethod.java
mn.aug.restfulandroid.rest.resource.Comment.java
mn.aug.restfulandroid.rest.resource.Lists.java
mn.aug.restfulandroid.rest.resource.Listw.java
mn.aug.restfulandroid.rest.resource.Login.java
mn.aug.restfulandroid.rest.resource.Reminder.java
mn.aug.restfulandroid.rest.resource.Resource.java
mn.aug.restfulandroid.rest.resource.TaskList.java
mn.aug.restfulandroid.rest.resource.Task.java
mn.aug.restfulandroid.rest.resource.Tasks.java
mn.aug.restfulandroid.rest.resource.Timer.java
mn.aug.restfulandroid.rest.resource.Timers.java
mn.aug.restfulandroid.security.AuthorizationManager.java
mn.aug.restfulandroid.security.RequestSigner.java
mn.aug.restfulandroid.service.ListProcessor.java
mn.aug.restfulandroid.service.ListsProcessor.java
mn.aug.restfulandroid.service.LoginProcessor.java
mn.aug.restfulandroid.service.ProcessorCallback.java
mn.aug.restfulandroid.service.ShareProcessor.java
mn.aug.restfulandroid.service.TaskProcessor.java
mn.aug.restfulandroid.service.TasksProcessor.java
mn.aug.restfulandroid.service.TimersProcessor.java
mn.aug.restfulandroid.service.WunderlistServiceHelper.java
mn.aug.restfulandroid.service.WunderlistService.java
mn.aug.restfulandroid.util.DateHelper.java
mn.aug.restfulandroid.util.DatePickerFragment.java
mn.aug.restfulandroid.util.Logger.java
mn.aug.restfulandroid.util.TimePickerFragment.java