//时间转换工具类 public class TimeUtils { /** * 时间戳转为时间(年月日,时分秒) * * @param cc_time 时间戳 * @return */ public static String getStrTime(String cc_time) { String re_StrTime = null; //同理也能够转为其它样式的时间格式.例如:"yyyy/MM/dd HH:mm" SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); // 例如:cc_time=1291778220 long lcc_time = Long.valueOf(cc_time); re_StrTime = sdf.format(new Date(lcc_time * 1000L)); return re_StrTime; } /** * 时间转换为时间戳 * * @param timeStr 时间 例如: 2016-03-09 * @param format 时间对应格式 例如: yyyy-MM-dd * @return */ public static long getTimeStamp(String timeStr, String format) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format); Date date = null; try { date = (Date) simpleDateFormat.parse(timeStr); long timeStamp = date.getTime(); return timeStamp; } catch (ParseException e) { e.printStackTrace(); } return 0; } //秒换算成小时 public static String formatTimeS(long seconds) { int temp = 0; StringBuffer sb = new StringBuffer(); if (seconds > 3600) { temp = (int) (seconds / 3600); sb.append((seconds / 3600) < 10 ? "0" + temp + ":" : temp + ":"); temp = (int) (seconds % 3600 / 60); changeSeconds(seconds, temp, sb); } else { temp = (int) (seconds % 3600 / 60); changeSeconds(seconds, temp, sb); } return sb.toString(); } private static void changeSeconds(long seconds, int temp, StringBuffer sb) { sb.append((temp < 10) ? "0" + temp + ":" : "" + temp + ":"); temp = (int) (seconds % 3600 % 60); sb.append((temp < 10) ? "0" + temp : "" + temp); } //获取系统时间戳 public String getTime(){ long time=System.currentTimeMillis()/1000;//获取系统时间的10位的时间戳 String str=String.valueOf(time); return str; } //获取系统时间 public String getTimes() { long currentTime = System.currentTimeMillis(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒"); Date date = new Date(currentTime); String format = formatter.format(date); return format; } }
Android自带的Base64加密android
import android.util.Base64;
String s= Base64.encodeToString("变量".getBytes(),Base64.DEFAULT);
解码:app
byte b[]=android.util.Base64.decode(字符串,Base64.DEFAULT); String 变量=new String(b); byte b[]=android.util.Base64.decode(字符串,Base64.DEFAULT);