上一秒位置java代码的简单介绍
用java如何实现 1小时前 1分钟前
/**
10年积累的成都网站制作、成都网站设计、外贸营销网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站制作后付款的网站建设流程,更有邱县免费网站建设让你可以放心的选择与我们合作。
* 显示时间,如果与当前时间差别小于一天,则自动用**秒(分,小时)前,如果大于一天则用format规定的格式显示
*
* @author wxy
* @param ctime
* 时间
* @param format
* 格式 格式描述:例如:yyyy-MM-dd yyyy-MM-dd HH:mm:ss
* @return
*/
public static String showTime(Date ctime, String format) {
String r = "";
if(ctime==null)return r;
if(format==null)format="yyyy-MM-dd HH:mm";
long nowtimelong = System.currentTimeMillis();
long ctimelong = ctime.getTime();
long result = Math.abs(nowtimelong - ctimelong);
if (result 60000)// 一分钟内
{
long seconds = result / 1000;
r = seconds + "秒钟前";
} else if (result = 60000 result 3600000)// 一小时内
{
long seconds = result / 60000;
r = seconds + "分钟前";
} else if (result = 3600000 result 86400000)// 一天内
{
long seconds = result / 3600000;
r = seconds + "小时前";
} else// 日期格式
{
r = DateTime.formatTime(ctime, format);
}
return r;
}
求java代码获取上个月最后一天最后一秒的时间
用这个方法吧:入参,可以是指定的日期, 返回 制定日期上个月最后一毫秒的时间点
public static Date getLastMonthEndTime(Date date){
Calendar c = Calendar.getInstance();
c.setTime(date);
c.add(Calendar.MONTH, -1);
c.set(Calendar.DAY_OF_MONTH,c.getActualMaximum(Calendar.DAY_OF_MONTH));//设置为最后一天
c.set(Calendar.HOUR_OF_DAY, 23);
c.set(Calendar.MINUTE, 59);
c.set(Calendar.SECOND, 59);
c.set(Calendar.MILLISECOND, 999);
return c.getTime();
}
自己用java写的分页,当点击下一页的时候 下一页数据出现在页面上一秒钟,页面数据就自动跳回到首页数据了
整体看,像是对数据的类型不太理解。
如 current++; ////////转成整数,再做++运算
JAVA秒表倒计时程序,用swing界面显示,请大家一定要帮帮小弟哈,我实在做不来这个,谢谢了。120分!!!
package com;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Tidy extends JFrame
{
private static final long serialVersionUID = 1L;
private static final String[] NS =
{ "秒表倒计时器", "时", "分", "秒", "请输入你倒计时的时间(分钟数):", "你一共用:", "时", "分", "秒", "开始倒计时", "暂停计时", "停止计时" };
private static int index = 0;
private long ms = 0;
private boolean isPaused = false;
private Timer timer;
public Tidy(String title)
{
setTitle(title);
}
private Tidy addComponents()
{
final JTextField[] ts = new JTextField[7];
for(int i = 0; i 7; i++)
{
ts[i] = new JTextField();
ts[i].setPreferredSize(new Dimension(50, 20));
if(i != 3)
{
ts[i].setEditable(false);
}
}
JLabel[] ls = new JLabel[9];
for(int i = 0; i 9; i++)
{
ls[i] = new JLabel(NS[index++]);
}
final JButton[] bs = new JButton[3];
for(int i = 0; i 3; i++)
{
bs[i] = new JButton(NS[index++]);
}
bs[0].addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
try
{
if(!isPaused)
{
long min = Long.parseLong(ts[3].getText());
long h = min / 60;
h = h 0 ? 0 : h;
long m = min - h * 60 - 1;
m = m 0 ? 0 : m;
long s = min == 0 ? 0 : 60;
ts[0].setText(h + "");
ts[1].setText(m + "");
ts[2].setText(s + "");
}
timer = new Timer();
timer.schedule(new TimerTask()
{
@Override
public void run()
{
long h = Long.parseLong(ts[0].getText());
long m = Long.parseLong(ts[1].getText());
long s = Long.parseLong(ts[2].getText());
s--;
ms++;
if((h != 0 || m != 0) s == 0)
{
m--;
s = 59;
}
if(h != 0 m == 0)
{
h--;
m = 59;
}
h = h 0 ? 0 : h;
m = m 0 ? 0 : m;
s = s 0 ? 0 : s;
ts[0].setText(h + "");
ts[1].setText(m + "");
ts[2].setText(s + "");
long ph = ms / 60 / 60;
long pm = ms / 60;
long ps = ms % 60;
ts[4].setText(ph + "");
ts[5].setText(pm + "");
ts[6].setText(ps + "");
if(h == 0 m == 0 s == 0)
{
bs[2].doClick();
}
}
}, 0, 1000);
bs[0].setEnabled(false);
}
catch(NumberFormatException nfe)
{
JOptionPane.showConfirmDialog(Tidy.this, "输入错误,请重新输入分钟的整数。", "友情提示", JOptionPane.PLAIN_MESSAGE,
JOptionPane.ERROR_MESSAGE);
}
}
});
bs[1].addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
if(null != timer)
{
timer.cancel();
timer = null;
}
bs[0].setEnabled(true);
isPaused = true;
}
});
bs[2].addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
if(null != timer)
{
timer.cancel();
timer = null;
}
bs[0].setEnabled(true);
isPaused = false;
ms = 0;
}
});
JComponent[][] cs = { { ls[0] }, { ts[0], ls[1], ts[1], ls[2], ts[2], ls[3] }, { ls[4], ts[3] },
{ ls[5], ts[4], ls[6], ts[5], ls[7], ts[6], ls[8] }, { bs[0], bs[1], bs[2] } };
JPanel[] ps = new JPanel[5];
JPanel wrap = new JPanel();
wrap.setLayout(new BoxLayout(wrap, BoxLayout.Y_AXIS));
for(int i = 0; i 5; i++)
{
ps[i] = new JPanel(new FlowLayout(FlowLayout.CENTER));
for(int j = 0; j cs[i].length; j++)
{
ps[i].add(cs[i][j]);
}
wrap.add(ps[i]);
}
add(wrap);
return this;
}
private Tidy init()
{
pack();
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
return this;
}
public static void main(String[] args)
{
Tidy tidy = new Tidy(NS[index]);
tidy.addComponents().init();
}
}
分享文章:上一秒位置java代码的简单介绍
本文路径:http://ybzwz.com/article/ddcphoj.html