宰猪好手
码龄7年
关注
提问 私信
  • 博客:8,592
    问答:2,507
    动态:89
    11,188
    总访问量
  • 1
    原创
  • 1,859,817
    排名
  • 2
    粉丝
  • 0
    铁粉

个人简介:作为程序员,学习就是我的使命。

IP属地以运营商信息为准,境内显示到省(区、市),境外显示到国家(地区)
IP 属地:广东省
  • 加入CSDN时间: 2018-03-19
博客简介:

weixin_41863683的博客

查看详细资料
个人成就
  • 获得3次点赞
  • 内容获得1次评论
  • 获得9次收藏
创作历程
  • 2篇
    2022年
  • 1篇
    2019年
成就勋章
创作活动更多

超级创作者激励计划

万元现金补贴,高额收益分成,专属VIP内容创作者流量扶持,等你加入!

去参加
  • 最近
  • 文章
  • 代码仓
  • 资源
  • 问答
  • 帖子
  • 视频
  • 课程
  • 关注/订阅/互动
  • 收藏
搜TA的内容
搜索 取消

【设计模式之美】如何面向开发一个需求

如何面向对象开发一个需求
翻译
发布博客 2022.07.21 ·
106 阅读 ·
0 点赞 ·
1 评论 ·
0 收藏

【设计模式之美】理解什么面向对象(What)、面向对象的作用(Why)、面向如何实现(How)

面向对象是啥
原创
发布博客 2022.07.10 ·
497 阅读 ·
0 点赞 ·
0 评论 ·
0 收藏

【设计模式之美】设计原则

设计原则
翻译
发布博客 2019.07.24 ·
240 阅读 ·
0 点赞 ·
0 评论 ·
0 收藏

如何创建Time class,求解一道题

答:

weilin

以下是解答
import java.util.Date;
import java.util.Calendar;
public class Time {

long hour,minute,second;
Date date;
Calendar calendar=Calendar.getInstance();
public Time(){
    this.date=new Date();   
}
public Time(long milliseconds){
    this.date=new Date(milliseconds);   
}
public Time(int hour,int minute,int second){
    long sum=0;
    sum=sum+hour*60*60*1000+minute*60*1000+second*1000;
    this.date=new Date(sum);
}
public long getHour() {
    hour=date.getTime()/3600000;
    return hour;
}
public long getMinute(){
     minute = (date.getTime() % 3600000) / 60000;
return minute;

}
public long getSecond() {
     second= (date.getTime() % 3600000) % 60000/1000;
    return second;  
}
public void setTime(long elapseTime) {
    Date newdate=new Date(elapseTime);
    date=newdate;   
}   

}

测试

public class Test {
public static void main(String args[]) {
Time time1=new Time();
Time time2=new Time(555550000);

    //System.out.println(time1.date);
    //System.out.println(time2.date);
    System.out.println("new Time()时分秒为:"+time1.getHour()+"时"+time1.getMinute()+"分"+time1.getSecond()+"秒");
    System.out.println("new Time(555550000)时分秒为:"+time2.getHour()+"时"+time2.getMinute()+"分"+time2.getSecond()+"秒");
}   

}

回答问题 2018.05.08