Back to project page CommonLibs.
The source code is released under:
Apache License
If you think the Android project CommonLibs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.alex.common.utils; /*from w w w .ja va2s .co m*/ import java.util.Calendar; import java.util.Date; import android.text.TextUtils; /** * ??????? * @author caisenchuan */ public class StringUtils { /*-------------------------- * ??? *-------------------------*/ /*-------------------------- * ????? *-------------------------*/ /*-------------------------- * ???????? *-------------------------*/ /*-------------------------- * public?? *-------------------------*/ /** * ????????????????,???????,????? * @param date - ??????? * @return ????? * @author caisenchuan **/ public static String getDateString(Date date) { Calendar c_t = Calendar.getInstance(); c_t.setTime(date); int y_t = c_t.get(Calendar.YEAR); int m_t = c_t.get(Calendar.MONTH) + 1; int d_t = c_t.get(Calendar.DAY_OF_MONTH); int h_t = c_t.get(Calendar.HOUR_OF_DAY); int mi_t = c_t.get(Calendar.MINUTE); Calendar c_now = Calendar.getInstance(); int y_now = c_now.get(Calendar.YEAR); int m_now = c_now.get(Calendar.MONTH) + 1; int d_now = c_now.get(Calendar.DAY_OF_MONTH); int h_now = c_now.get(Calendar.HOUR_OF_DAY); int mi_now = c_now.get(Calendar.MINUTE); System.out.println(String.format("%s %s %s %s %s", y_t, m_t, d_t, h_t, mi_t)); System.out.println(String.format("%s %s %s %s %s", y_now, m_now, d_now, h_now, mi_now)); String ret = String.format("%s?%s?%s?", y_t, m_t, d_t); int diff = 0; if(c_t.after(c_now)) { //????????? } else if(y_t < y_now) { //??????? } else if(m_t < m_now) { //???? ret = String.format("%s?%s?", m_t, d_t); } else if(d_t < d_now) { //X??? diff = d_now - d_t; if(diff == 1) { ret = "??"; } else { ret = diff + "???"; } } else if(h_t < h_now) { //X????? diff = h_now - h_t; ret = diff + "?????"; } else if(mi_t < mi_now) { //X???? diff = mi_now - mi_t; ret = diff + "????"; } else { ret = "??"; } return ret; } /** * ?????????? * @param text * @return * @author caisenchuan */ public static String getStripContent(String text) { String ret = ""; if(!TextUtils.isEmpty(text)) { int i = text.indexOf("????"); if(i > 0) { ret = text.substring(0, i); } } return ret; } /** * ??????????? * @param url * @return */ public static boolean isLocalUri(String url) { boolean ret = false; if(url != null && (url.startsWith("file://") || url.startsWith("/"))) { ret = true; } return ret; } /*-------------------------- * protected??packet?? *-------------------------*/ /*-------------------------- * private?? *-------------------------*/ }