Test

import  java.util.*;
import java.text.*;

SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
long lastTime = 1564976716;
int beforeTime = 0;
Date dNow = new Date(lastTime * 1000);
System.out.println("当前时间为: " + ft.format(dNow));

当前时间为: 2019-08-05 11:45:16

double lastTimestamp = 0.0;
boolean a = lastTimestamp.equal(0);
System.out.print(a);
|   boolean a = lastTimestamp.equal(0);

double cannot be dereferenced
import java.util.Date;
import java.text.SimpleDateFormat;

// Date 对象
// 当前时间
// Date();
// timestamp(long) --> Date 对象
// Date(long millisec);

SimpleDateFormat ft = new SimpleDateFormat ("ss");
String now = ft.format(new Date());
System.out.print(now);
35
import java.util.Date;
import java.text.SimpleDateFormat;
import java.text.DateFormat;

long timestamp = 1564731804;
// System.out.print(timestamp);

// long now = (new Date()).getTime();
// System.out.print(now);
Date dt = new Date(timestamp);
DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String tsStr = sdf.format(dt);
System.out.print(tsStr);

1970/01/19 10:38:51
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.time.ZoneOffset;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

// Map<Integer, Map<String, Double>> oriDataMapNew = new HashMap<>();
// Map<String, Double> oriDataTmp = new HashMap<>();
// int nowSecond = Integer.parseInt(LocalDateTime.now().format(DateTimeFormatter.ofPattern("ss")));

// long now = System.currentTimeMillis();
// int internal = 10;
// long index = now / 1000 % internal;
// String key = new String();
// double value = 0.0;
String getTimeZone(){
    Calendar cal = Calendar.getInstance();
    int offset = cal.get(Calendar.ZONE_OFFSET);
    cal.add(Calendar.MILLISECOND, -offset);
    Long timeStampUTC = cal.getTimeInMillis();
    Long timeStamp = System.currentTimeMillis();
    Long timeZone = (timeStamp - timeStampUTC) / (1000 * 3600); System.out.println(timeZone.intValue());
    return String.valueOf(timeZone);
}

// System.out.print(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss:SSS").withZone(ZoneId.of("Asia/Shanghai"))));
System.out.print(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss:SSS")));
System.out.print(getTimeZone() + "\n");


LocalDateTime now = LocalDateTime.now();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
System.out.println ("默认格式化:" + now);
System.out.println ("自定义格式化:" + now.format (dateTimeFormatter));

2019-08-01 15:29:50:1568
8
默认格式化:2019-08-01T15:29:50.420507
自定义格式化:2019-08-01 15:29:50

Avatar
叶王
高级研发工程师

目前主要从事软件后台开发