当前位置: 技术问答>java相关
在APPLET中如何获得系统时间??
来源: 互联网 发布时间:2015-05-27
本文导语: 用什么样的函数? | 具体自己改一下 import java.util.*; public class DateAndTime { private static GregorianCalendar gCalendar= new GregorianCalendar(); public DateAndTime() {} public static String getTime() { g...
用什么样的函数?
|
具体自己改一下
import java.util.*;
public class DateAndTime
{
private static GregorianCalendar gCalendar= new GregorianCalendar();
public DateAndTime()
{}
public static String getTime()
{
gCalendar.setTimeInMillis(System.currentTimeMillis());
return new String
(
gCalendar.get(Calendar.HOUR_OF_DAY) +":" +
gCalendar.get(Calendar.MINUTE) +":" +
gCalendar.get(Calendar.SECOND)
);
}
public static String getDate()
{
gCalendar.setTimeInMillis(System.currentTimeMillis());
return new String
(
gCalendar.get(Calendar.YEAR) +"/" +
gCalendar.get(Calendar.MONTH) +"/" +
gCalendar.get(Calendar.DAY_OF_MONTH)
);
}
public static void main(String[] args) throws Exception
{
System.out.println(getDate());
System.out.println(getTime());
}
}
import java.util.*;
public class DateAndTime
{
private static GregorianCalendar gCalendar= new GregorianCalendar();
public DateAndTime()
{}
public static String getTime()
{
gCalendar.setTimeInMillis(System.currentTimeMillis());
return new String
(
gCalendar.get(Calendar.HOUR_OF_DAY) +":" +
gCalendar.get(Calendar.MINUTE) +":" +
gCalendar.get(Calendar.SECOND)
);
}
public static String getDate()
{
gCalendar.setTimeInMillis(System.currentTimeMillis());
return new String
(
gCalendar.get(Calendar.YEAR) +"/" +
gCalendar.get(Calendar.MONTH) +"/" +
gCalendar.get(Calendar.DAY_OF_MONTH)
);
}
public static void main(String[] args) throws Exception
{
System.out.println(getDate());
System.out.println(getTime());
}
}
|
以上方法也适用于javaBean
上面的是jdk1.4版本
下面的应该没问题
import java.util.*;
public class DateAndTime
{
private static GregorianCalendar gCalendar= new GregorianCalendar();
public DateAndTime()
{}
public static String getTime()
{
// gCalendar.setTimeInMillis(System.currentTimeMillis()); jdk1.4 only
gCalendar.setTime(new Date());
return new String
(
gCalendar.get(Calendar.HOUR_OF_DAY) +":" +
gCalendar.get(Calendar.MINUTE) +":" +
gCalendar.get(Calendar.SECOND)
);
}
public static String getDate()
{
// gCalendar.setTimeInMillis(System.currentTimeMillis());
gCalendar.setTime(new Date());
return new String
(
gCalendar.get(Calendar.YEAR) +"/" +
gCalendar.get(Calendar.MONTH) +"/" +
gCalendar.get(Calendar.DAY_OF_MONTH)
);
}
public static void main(String[] args) throws Exception
{
System.out.println(getDate());
System.out.println(getTime());
}
}
上面的是jdk1.4版本
下面的应该没问题
import java.util.*;
public class DateAndTime
{
private static GregorianCalendar gCalendar= new GregorianCalendar();
public DateAndTime()
{}
public static String getTime()
{
// gCalendar.setTimeInMillis(System.currentTimeMillis()); jdk1.4 only
gCalendar.setTime(new Date());
return new String
(
gCalendar.get(Calendar.HOUR_OF_DAY) +":" +
gCalendar.get(Calendar.MINUTE) +":" +
gCalendar.get(Calendar.SECOND)
);
}
public static String getDate()
{
// gCalendar.setTimeInMillis(System.currentTimeMillis());
gCalendar.setTime(new Date());
return new String
(
gCalendar.get(Calendar.YEAR) +"/" +
gCalendar.get(Calendar.MONTH) +"/" +
gCalendar.get(Calendar.DAY_OF_MONTH)
);
}
public static void main(String[] args) throws Exception
{
System.out.println(getDate());
System.out.println(getTime());
}
}