Example usage for java.text DateFormat getDateTimeInstance

List of usage examples for java.text DateFormat getDateTimeInstance

Introduction

In this page you can find the example usage for java.text DateFormat getDateTimeInstance.

Prototype

public static final DateFormat getDateTimeInstance() 

Source Link

Document

Gets the date/time formatter with the default formatting style for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static String formatDateTime(Date paramDate) {
    return format(paramDate, DateFormat.getDateTimeInstance());
}

From source file:Main.java

/**
 * Converts Unix time to human readable format
 * @param milliseconds that have passed since 01/01/1970
 * @return The human readable time for the users locale
 *//*from   w  w  w.ja va  2 s. co  m*/
public static String unixTimeToHumanReadable(long milliseconds) {
    Date date = new Date(milliseconds);
    DateFormat df = DateFormat.getDateTimeInstance();
    return df.format(date);
}

From source file:Main.java

public static String DateMessage(Date d, Context c) {
    DateFormat df = DateFormat.getDateTimeInstance();
    DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    DateFormat dfNoTime = DateFormat.getDateInstance();
    DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
    DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
    DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH);
    DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c);

    String s = dfDevice.format(d) + " or \n" + dfS.format(d) + " or \n" + dfM.format(d) + " or \n"
            + dfL.format(d) + " or \n" + dfF.format(d);

    return s;//from ww  w  . j  a va2  s . co m

}

From source file:Main.java

public static Date FormatDate(String sRecDate, Context c) {
    DateFormat df = DateFormat.getDateTimeInstance();
    DateFormat dfS = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    DateFormat dfM = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
    DateFormat dfL = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
    DateFormat dfF = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    DateFormat dfNoTime = DateFormat.getDateInstance();
    DateFormat dfSNoTime = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
    DateFormat dfMNoTime = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
    DateFormat dfLNoTime = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
    DateFormat dfFNoTime = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH);
    DateFormat dfDevice = android.text.format.DateFormat.getDateFormat(c);

    Date dRecDate = null;/* ww w . j a va  2 s  . co m*/

    try {
        dRecDate = dfDevice.parse(sRecDate);
    } catch (ParseException e) {
        try {
            dRecDate = df.parse(sRecDate);
        } catch (ParseException e2) {

            try {
                dRecDate = dfS.parse(sRecDate);
            } catch (ParseException e3) {

                try {
                    dRecDate = dfM.parse(sRecDate);
                } catch (ParseException e4) {

                    try {
                        dRecDate = dfL.parse(sRecDate);
                    } catch (ParseException e5) {

                        try {
                            dRecDate = dfF.parse(sRecDate);
                        } catch (ParseException e6) {

                            try {
                                dRecDate = dfNoTime.parse(sRecDate);
                            } catch (ParseException e7) {

                                try {
                                    dRecDate = dfSNoTime.parse(sRecDate);
                                } catch (ParseException e8) {

                                    try {
                                        dRecDate = dfMNoTime.parse(sRecDate);
                                    } catch (ParseException e9) {

                                        try {
                                            dRecDate = dfLNoTime.parse(sRecDate);
                                        } catch (ParseException e10) {

                                            try {
                                                dRecDate = dfFNoTime.parse(sRecDate);
                                            } catch (ParseException e11) {

                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return dRecDate;

}

From source file:com.twinsoft.convertigo.engine.util.CookiesUtils.java

public static String formatCookie(Cookie cookie) {
    StringBuffer buf = new StringBuffer();
    Date d = cookie.getExpiryDate();
    String[][] datas = {//from  www.  j a v a  2s  .c  o m
            // {"$Version",Integer.toString(cookie.getVersion())},
            { cookie.getName(), cookie.getValue() }, { "$Domain", cookie.getDomain() },
            { "$Path", cookie.getPath() }, { "$Secure", Boolean.toString(cookie.getSecure()) },
            { "$Date", d == null ? "null" : DateFormat.getDateTimeInstance().format(d) } };
    buf.append(datas[0][0] + "=" + datas[0][1]);
    for (int i = 1; i < datas.length; i++) {
        if (datas[i][1] != null)
            buf.append("; " + datas[i][0] + "=" + datas[i][1]);
    }
    return buf.toString();
}

From source file:org.flowable.bpmn.model.DateDataObject.java

@Override
public void setValue(Object value) {
    if (value instanceof String && !StringUtils.isEmpty(((String) value).trim())) {
        try {//from  ww  w . j ava2 s  . co  m
            this.value = DateFormat.getDateTimeInstance().parse((String) value);
        } catch (ParseException e) {
            System.out.println("Error parsing Date string: " + value);
        }
    } else if (value instanceof Date) {
        this.value = value;
    }
}

From source file:Main.java

public void tickTock() {
    clock.setText(DateFormat.getDateTimeInstance().format(new Date()));
}

From source file:edu.umd.cs.hcil.twitterreplay.ProducerTask.java

public ProducerTask(Date firstTime, int interval, int unit, GzippedFileReader input) {

    mInterval = interval;/*from  w  w  w  .ja  v  a  2 s . co  m*/
    mIntervalUnit = unit;

    mDateFormat = DateFormat.getDateTimeInstance();
    mCalendar = Calendar.getInstance();
    mCalendar.setTime(firstTime);
    mCalendar.add(mIntervalUnit, mInterval);

    mCurrentTime = firstTime;
    mNextTime = mCalendar.getTime();

    mNextItem = null;

    mInputReader = input;
}

From source file:Main.java

/**
 * Creates a media file in the {@code Environment.DIRECTORY_PICTURES} directory. The directory
 * is persistent and available to other applications like gallery.
 *
 * @param type Media type. Can be video or image.
 * @return A file object pointing to the newly created file.
 *///from   w w w .j  a v  a  2 s  .c  o m
public static File getOutputMediaFile(int type) {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.
    if (!Environment.getExternalStorageState().equalsIgnoreCase(Environment.DIRECTORY_MOVIES)) {
        return null;
    }

    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES),
            "ViewBody");
    // This location works best if you want the created images to be shared
    // between applications and persist after your app has been uninstalled.

    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("CameraSample", "failed to create directory");
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyMMdd_HHmmss", Locale.KOREAN)
            .format(DateFormat.getDateTimeInstance());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
    } else if (type == MEDIA_TYPE_VIDEO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "ViewBody_" + timeStamp + ".mp4");
    } else {
        return null;
    }

    return mediaFile;
}

From source file:org.openhab.habdroid.ui.AboutFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.openhababout, container, false);

    TextView about = (TextView) view.findViewById(R.id.license_link);
    about.setText(Html.fromHtml(getString(R.string.about_license)));
    about.setMovementMethod(LinkMovementMethod.getInstance());
    TextView appVersion = (TextView) view.findViewById(R.id.app_version);
    appVersion.setText(getString(R.string.about_version_string, BuildConfig.VERSION_NAME,
            DateFormat.getDateTimeInstance().format(BuildConfig.buildTime)));

    String year = new SimpleDateFormat("yyyy", Locale.US).format(Calendar.getInstance().getTime());
    TextView copyright = (TextView) view.findViewById(R.id.copyright);
    copyright.setText(String.format(getString(R.string.about_copyright), year));
    copyright.setMovementMethod(LinkMovementMethod.getInstance());

    TextView links = (TextView) view.findViewById(R.id.links_list);
    links.setText(Html.fromHtml(getString(R.string.about_links_list)));
    links.setMovementMethod(LinkMovementMethod.getInstance());

    return view;//from ww w.j  a va  2  s. com
}