发表于: 2018-01-15 21:50:14

1 617


今天完成的事情:

今天送给自己一首歌,我们不一样。

今天 和师兄一起商量做出了一个重要的Demo,把收藏列表排序然后发送给前端,这个很重要。

//返回对应的字符串类型给前端。

package util;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeFormatUtil {
public static String  main(Long l) {
// 定义最终返回的结果字符串。
     String interval = null;
     long s =new Date().getTime()-l;
     long millisecond = new Date().getTime() - s;
//    System.out.println(new Date().getTime());
//    System.out.println(createAt.getTime());
     System.out.println(millisecond);
     long second = millisecond / 1000;
     System.out.println(second);
//long second=1;
     if (second <= 0) {
second = 0;
     }
//*--------------微博体(标准)
     if (second == 0) {
interval = "刚刚";
     } else if (second < 30) {
interval = second + "秒以前";
     } else if (second >= 30 && second < 60) {
interval = "半分钟前";
     } else if (second >= 60 && second < 60 * 60) {//大于1分钟 小于1小时
        long minute = second / 60;
        interval = minute + "分钟前";
     } else if (second >= 60 * 60 && second < 60 * 60 * 24) {//大于1小时 小于24小时
        long hour = (second / 60) / 60;
        if (hour <= 3) {
interval = hour + "小时前";
        } else {
interval = "今天" + getFormatTime(s, "HH:mm");
        }
} else if (second >= 60 * 60 * 24 && second <= 60 * 60 * 24 * 2) {//大于1D 小于2D
        interval = "昨天" + getFormatTime(s, "HH:mm");
     } else if (second >= 60 * 60 * 24 * 2 && second <= 60 * 60 * 24 * 7) {//大于2D小时 小于 7
        long day = ((second / 60) / 60) / 24;
        interval = day + "天前";
     } else if ( second <= 60 * 60 * 24 * 365 && second >= 60 * 60 * 24 * 7) {//大于7天小于365
        interval = getFormatTime(s, "MM-dd HH:mm");
     } else if (second >= 60 * 60 * 24 * 365) {//大于365
        interval = getFormatTime(s, "yyyy-MM-dd HH:mm");
     } else {
interval = "0";
     }
System.out.println(interval);
     return interval;
  }
public static String getFormatTime(Long l, String Sdf) {
return (new SimpleDateFormat(Sdf)).format(l);
  }
// public static void main(String[] args) {
//    try {
//       System.out.println(getInterval(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2017-01-15 15:12:12")));
//    } catch (ParseException e) {
//       e.printStackTrace();
//    }
// }

}



//这个工具把对应的list集合排序 然后按顺序输出。

这里很巧妙的使用了另一个类,增加了一个字段。

package util;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ssh.entity.Student;
import com.ssh.entity.Studentt;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;


public class Json {
public static void main(String[] args) {
//Student s = new Student();
       Student student1 = new Student(1, "Aaron", 240000L);
       Student student2 = new Student(2, "Aaron", 220000L);
       Student student3 = new Student(3, "Aaron", 2300000L);
       List<Student> ss=new ArrayList<Student>();
       ss.add(student1);
       ss.add(student2);
       ss.add(student3);

       List<Studentt> list2 = new ArrayList<Studentt>();
       for (Student student : ss) {
Studentt st=new Studentt();
           BeanUtils.copyProperties(student,st);
           Long a=st.getAge();
           String g=TimeFormatUtil.main(a);
           st.setInv(g);
           list2.add(st);
       }

System.out.println(list2);

       Map<Object,Object> map=new TreeMap();

       for(Studentt t:list2 ){
map.put(t.getAge(),t);
       }
System.out.println(map);

//        JSONObject json = new JSONObject();
//        json.put("code",200);
//        json.put("data",map);
//        System.out.println(json);
       org.json.JSONObject jsonObject = new org.json.JSONObject();
       jsonObject.put("data",map);
       System.out.println(jsonObject);

//        map.putAll(map<>);
//        map.put(student1.getAge(),student1);
//        map.put(student2.getAge(),student2);
//        map.put(student3.getAge(),student3);
//        for(Map.Entry<Object, Object> entry:map.entrySet()){
//            s=(Student) entry.getValue();
//            System.out.println(s.getAge());
//            System.out.println(s);
//        }
//        System.out.println(map);
   }
}


明天计划的事情:

明天继续研究复盘中可能会遇见的问题。
遇到的问题:

对json不熟练。
收获:

这两个demo很重要的。


返回列表 返回列表
评论

    分享到