非常有用的Java日期时间操作函数代码一览
/**
日期类
* @date
* @version 1.0
*/
import java.util.*;
import java.text.*;
import java.util.Calendar;
public class VeDate {
/**
* 获取现在时间
*
* @return 返回时间类型 yyyy-MM-dd HH:mm:ss
*/
public static Date getNowDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
/**
* 获取现在时间
*
* @return返回短时间格式 yyyy-MM-dd
*/
public static Date getNowDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
/**
* 获取现在时间
*
* @return返回字符串格式 yyyy-MM-dd HH:mm:ss
*/
public static String getStringDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
return dateString;
}
/**
* 获取现在时间
*
* @return 返回短时间字符串格式yyyy-MM-dd
*/
public static String getStringDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
re
相关文档:
import java.awt.*;
import javax.swing.*;
import java.util.Date;
import java.awt.*;
class Time extends JFrame implements Runnable{//实现接口
Thread clockThread;
JLabel jLabel=new JLabel();
public Time()
{
Container con=this.getContentPane() ......
对于学习static我们先来看两个例子:
//Example 1 Tst.java,no main() method
package com.blogchina.qb2049;
public class Tst
{
static { System.out.println("111111"); }
}
运行结果为: 111111
Exception in thread "main" java.lang.NoSuchMethodError: main
同样的道理看第二 ......
1.List转换成为数组。(这里的List是实体是ArrayList)
调用ArrayList的toArray方法。
例:String[] arr = (String[])list.toArray(new String[size]);
2.数组转换成为List。
调用Arrays的asList方法。
例:List stooges = Arrays.asList("Larry", "Moe", "Curly"); ......
1、FACTORY(工厂模式)
2、BUILDER(建造模式)
3、FACTORY METHOD(工厂方法模式)
4、PROTOTYPE(原始模型模式)
5、SINGLETON(单例模式)
6、ADAPTER(适配器模式)
7、BRIDGE(桥梁模式)
8、COMPOSITE(合成模式)
9、DECORATOR(装饰模式)
10、FACADE(门面模式)
11、FLYWEIGHT(享元模式) ......