Time tool class, Base64 encryption

//Time conversion tool class
public class TimeUtils {
    /**
     * Timestamp to time (year month day, hour minute second)
     *
     * @param cc_time timestamp
     * @return
     */
    public static String getStrTime(String cc_time) {
        String re_StrTime = null;
        //Similarly, it can also be converted to other time formats. For example: "yyyy/MM/dd HH:mm"
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        // For example: cc_time=1291778220
        long lcc_time = Long.valueOf(cc_time);
        re_StrTime = sdf.format(new Date(lcc_time * 1000L));

        return re_StrTime;
    }

    /**
     * Convert time to timestamp
     *
     * @param timeStr time example: 2016-03-09
     * @param format Time corresponding format for example: 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;
    }

    // convert seconds to hours
    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);
    }

    //Get the system timestamp
    public String getTime(){
        long time=System.currentTimeMillis()/1000;//Get the 10-digit timestamp of the system time
        String  str=String.valueOf(time);
        return str;
    }

    //get system time
    public String getTimes() {
        long currentTime = System.currentTimeMillis();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy year - MM month dd day - HH hour mm minute ss second");
        Date date = new Date(currentTime);
        String format = formatter.format(date);
        return format;
    }
}

 

Android comes with Base64 encryption

import android.util.Base64;
String s= Base64.encodeToString("变量".getBytes(),Base64.DEFAULT);

decoding:

byte b[]=android.util.Base64.decode(string, Base64.DEFAULT);
String variable=new String(b);
byte b[]=android.util.Base64.decode(string, Base64.DEFAULT);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325322939&siteId=291194637