获取当前日期和随机数

1.获取当前日期

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

public class DateDemo
{
  public static void main(String[] args){

  Date date = new Date();
  SimpleDateFormat sdf = new SimpleDateFormat("yy/MM/dd HH:mm:ss");
  String now = sdf.format(date);
  System.out.println(now);
  
  }
}

2.获取随机数

import java.util.Random;
public class RandomDemo
{
  public static void main(String[] args){

  Random random = new Random();
  int i = random.nextInt(10);
  System.out.println(i);
  }
}

posted @ 2013-03-10 00:36  hacket520  阅读(351)  评论(0编辑  收藏  举报