一、.获取系统的时间
1.)
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String time = formatter.format(new Date());//获取到当前的系统时间精确到年月日精确到毫秒
结果:20170425112526513
2.)
时间戳的默认单位是毫秒,System.currentTimeMillis(); 返回的就是以毫秒为单位的系统时间戳
Long time= System.currentTimeMillis();//获取当前的系统时间精确到毫秒 Long型(用于时间戳)
结果:1493089570240
3.)
long currentTime = System.currentTimeMillis();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
Date date = new Date(currentTime);
System.out.println(formatter.format(date));
运行结果如下:
当前时间:2011年-08月10日-14时11分46秒
时间转换:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); holder.order_time.setText(format.format(mList.get(position).getCreateTime().toString()));运行结果如下:2016-11-28 19:20
二、字符串的转换
3.)Long型转成string
String time=Long.toString(time);
4.)把java对象转成json
Been been = new Been(); been.setTradingId(mTradingId);
String str = new Gson().toJson(been);
5.)string转byte[]
String str="aaaaaaaaaa";
byte[] srtbyte =str.getBytes();byte[] srtbyte = str.getBytes("UTF-8");
6.)byte[]转string
byte[] encodedData = RSACoder.encryptByPublicKey(data, publicKey);
String param = new String(encodedData);//不带编码格式的
String param = new String(encodedData,"UTF-8");//带编码格式的
三、)字符串的处理
字符串截取
1.)
String url=""https://image.baidu.com/"";
url = baseUrl.substring(0, baseUrl.lastIndexOf("/")) + ":newNetLottery_web3g/index.html";结果:https://image.baidu.com:newNetLottery_web3g/index.html2.)
String imageUrl="https://www.baidu.com/img1.jpg,https://image.baidu.com/img2jpg,https://image.baidu.com/img3jpg";
String[] imgs = imageUrl.split(","); for (int i = 0; i < imgs.length; i++) { paths.add(imgs[i]); }结果:https://www.baidu.com/img1.jpghttps://image.baidu.com/img2jpghttps://image.baidu.com/img3jpg
四、)加密,解密
String str = new Gson().toJson(been); byte[] data = str.getBytes(); //加密 String publicKey = DataCenter.getCommonData().PUBLIC_KEY; byte[] encodedData = RSACoder.encryptByPublicKey(data, publicKey); String param = byteArr2HexStr(encodedData); //解密 byte[] ss=hexStr2ByteArr(param); String private_key = DataCenter.getCommonData().PRIVATE_KEY; byte[] privateDate=decryptByPrivateKey(ss, private_key); String aa = new String(privateDate); Log.e("TAG", "解密param++++++++++++" + aa);1、ArrarList 转换为 string[] :
ArrayList list = new ArrayList();
list.Add("aaa");
list.Add("bbb");
string[] arrString = (string[])list.ToArray(typeof( string)) ;
2、string[] 转换为 ArrarList :
ArrayList list = new ArrayList(new string[] { "aaa", "bbb" });
3、ArrayList 转换为 string :
ArrayList list = new ArrayList();
list.Add("aaa");
list.Add("bbb");
string str= string.Join(",", (string[])list.ToArray(typeof( string)));
4、string 转换为 ArrayList :
string str="1,2,3,4,5";
ArrayList b = new ArrayList( str.Split(',') ) ;