java时间格式时间戳互转换,排序等功能,
package com.bjsasc.avplan.middleware.service.timeproportion.timeProportionimpl;
import java.math.BigDecimal;
DateFormat;
DecimalFormat;
SimpleDateFormat;
import java.util.Map;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;java时间日期格式转换
import java.util.Map;
import java.util.TimeZone;
import com.bjsasc.avplan.middleware.util.timescale.TimeCalculateUtil;
import oracle.sql.DATE;
public class ListTest {
public static void main(String[] args) {
// new ListTest().bubbleSort();
}
/**
* 冒泡排序法
* 1、从⼤到⼩排序:新建java类,定义⼀个⽅法(如:bigAndSmall)并声明⼀个数组。如:int arr[] = {-5,29,7,10,5,16}; 如下图所⽰:
* 2、根据数组的长度循环遍历,并判断如果前⼀个值⼩于后⼀个值,那么就把“后⼀个值”排列到“当前前⼀个值”的前⾯。循环⽅式见下图所⽰
* 3、通过FOR循环取出最后的排序。如下图所⽰:
* 4、在main函数中,通过实例化别名点⽅法名的⽅式调⽤并打印出结果。
* 5、从⼩到⼤排序:与从⼤到⼩不同之处就是将⼩的换到前⾯去,⼤的排后。⽽且在“从⼤到⼩”的基础上,修改⼀下符号即可。循环⽅式如下图所⽰: * 6、然后在main函数中,通过实例化别名点⽅法名的⽅式调⽤并打印出从⼩到⼤排序结果。如下图所⽰:
* 7、以“从⼩到⼤”为例,打印实际循环过程,如下图添加sys打印语句即可。
*/
public void bubbleSort() {
int arr[] = { 8, 5, 2, 11, 9, 12 };
for (int i = 0; i < arr.length; i++) {
System.out.println("当 i = "+i+"时:");
for (int j = 0; j < arr.length - 1; j++) {
if (arr[j] > arr[j + 1]) {
int temp;
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
System.out.println("第J" +j+ "时:"+arr[0]+","+arr[1]+","+","+arr[2]+","+","+arr[3]+","+","+arr[4]+","+","+arr[5]);
}
System.out.println("for循环结果为: "+arr[0]+","+arr[1]+","+","+arr[2]+","+","+arr[3]+","+","+arr[4]+","+","+arr[5]);
}
for (int i = 0; i < arr.length; i++) {
System.out.println("其值为:" + arr[i]);
}
}
}
多个数据拼成⼀个字符串加双引号
String termStr = "";
StringBuffer term = new StringBuffer();
if(listd.size()!=0){
term = term.append(" in (");
for(int i=0;i<listd.size();i++){
term.append("'"+(i)+"'");
if(i==listd.size()-1){
term.append(") ");
}else{
term.append(",");
}
}
termStr = String();
}
例如 : in (‘16254037’,‘16201067’,‘16104005’)
//--------------------------------------------------------------------------------
listd = [16254037,16201067,16104005]
String str = String().replaceAll("\\[|\\]", "");
str = 16254037,16201067,16104005
//encodeURIComponent(id) JS编码格式,将传过来的id乱码转换,java解码id = URLDecoder.decode(id, "UTF-8");  //将取过来的id放置在decode即可转换
//根据括号截取字符串
String ss = "张耀华(zyh)";
int s = ss.indexOf("(");
String w = ss.substring(0,s);
System.out.println(w);
//拆分字符串并且给拆分开的字符串拼⼀个字符
String ssw = "张耀华(zyh)";
String[] sv = ssw.split("\\(");
for (int i = 0; i < sv.length; i++) {
System.out.println(sv[i]);
}
String d1 = sv[0];
String d2 = sv[1];
System.out.println(d1+d2);
String d3 =  d1+"#("+d2;
System.out.println(d3);
/
/将时间格式转换为毫秒数
public static long mills(String tre){
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置⽇期格式
try {
long mill = df.parse(tre).getTime();
System.out.println(mill+"将时间格式转换为毫秒数");
times(mill);
return mill;
} catch (ParseException e) {
// TODO Auto-generated catch block
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
//这个是将毫秒转为时间格式
public static String times(long time){
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Instance();
calendar.setTimeInMillis(time);
String temp = formatter.Time());
System.out.println(temp+"这个是将毫秒转为时间格式");
return temp;
}
/**
* 时间戳和天数相加
*/
public static String plusDay(long newDate, int num) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = Instance();
calendar.setTimeInMillis(newDate);
// calendar.set(Calendar.DATE,num);
calendar.add(Calendar.DAY_OF_MONTH, num);
String temp = formatter.Time());
Date date;
String res = null;
try {
date = formatter.parse(temp);
long ts = Time();
res = String.valueOf(ts);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return res;
}
//毫秒数⽇期加上或者减去天数,这个是有天数参数的相加的⽅法
public static Long timeMillisconver(long pram, String prams) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Instance();
calendar.setTimeInMillis(pram);
// String timeFormat ="yyyy-MM-dd_HH:mm:ss";
if (Integer.parseInt(prams) > 0) {
calendar.add(Calendar.DAY_OF_MONTH, Integer.parseInt(prams) - 1); } else {
calendar.add(Calendar.DAY_OF_MONTH, Integer.parseInt(prams));
}
// calendar.add(Calendar.DAY_OF_MONTH,Integer.parseInt(prams));
String times = formatter.Time());
System.out.println("更改后的时间:" + prams);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dt;
Long longtime = null;
try {
dt = sdf.parse(times);
longtime = dt.getTime();
longtime = dt.getTime();
// System.out.println("----------:"+longtime);
// return ssd;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return longtime;
}
//毫秒数⽇期加上或者减去天数,这个是直接赋值加或者减去的天数
public static Long timeMillisconvers(long pram) {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar calendar = Instance();
calendar.setTimeInMillis(pram);
/
/ String timeFormat ="yyyy-MM-dd_HH:mm:ss";
calendar.add(Calendar.DAY_OF_MONTH,  - 2);
// calendar.add(Calendar.DAY_OF_MONTH,Integer.parseInt(prams));
String times = formatter.Time());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date dt;
Long longtime = null;
try {
dt = sdf.parse(times);
longtime = dt.getTime();
// System.out.println("----------:"+longtime);
/
/ return ssd;
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return longtime;
}
//截取并且获得最后⼀个字符
char pelanned = CharArray()[ CharArray().length-1];
CSS 样式
.wrapace{
/
! 如果需要在td⾥⾯给过长的数据隐藏就需要以下属性,在此基础上要将tableLayout:'fixed’属性定义在table上 !/ z-index: 100;
width: 100%; /设置需要固定的宽度/
height:30px;
white-space: nowrap; /不换⾏/
text-overflow: ellipsis; /超出部分⽤…代替/
overflow: hidden; /!!* 超出隐藏*!!!/
border:1px solid #00163e;
text-align:center;
font-size:18px;
color:#fff;
-moz-text-overflow: ellipsis;/超出部分不⽤…代替 /
word-wrap:break-word; / ! tableLayout:‘fixed td换⾏属性’!*/
}
//将json的多组数据转换成list对象集合
String json = loadJson(url);
List list = new ArrayList<>();
JSONObject obj = JSONObject.fromObject(json);
//   json对象转换成list集合:
String recordCount = String(“total”);
JSONArray objData =  (("items"); //获取data字段
list=(List<Bomstage>)Collection(objData, Bomstage.class);
//处理远程接⼝
public static String loadJson(String url){
StringBuilder json = new StringBuilder();
try
{
URL urlObject = new URL(url);
URLConnection uc = urlObject.openConnection();
BufferedReader in = new BufferedReader(new InputStream(), “GBK”));//编码类型String inputLine = null;
while ((inputLine = in.readLine()) != null)
{
json.append(inputLine);
}
in.close();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
String();
}
//根据⽇期得到今天星期⼏

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。