首页 > 系统 > Android > 正文

Android开发获取当前系统日期和时间功能示例

2019-12-12 00:13:12
字体:
来源:转载
供稿:网友

本文实例讲述了Android开发获取当前系统日期和时间功能。分享给大家供大家参考,具体如下:

安卓 获得系统时间

public class MainActivity extends AppCompatActivity {  @Override  protected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    //创建线性布局管理器    LinearLayout layout = new LinearLayout(this);    //显示改layout    super.setContentView(layout);    layout.setOrientation(LinearLayout.VERTICAL); //创建TextView    final TextView show = new TextView(this); //创建Button    Button bn = new Button(this);    bn.setText(R.string.ok);    bn.setLayoutParams(new ViewGroup.LayoutParams(        ViewGroup.LayoutParams.WRAP_CONTENT,        ViewGroup.LayoutParams.MATCH_PARENT)); //添加TextView    layout.addView(show); //添加Button    layout.addView(bn); //设置一个监听事件    bn.setOnClickListener(new View.OnClickListener() {      @Override      public void onClick(View v) {        show.setText("hello , Android , " + new java.util.Date());      }    });  }}

获得时间

show.setText("hello , Android , " + new java.util.Date());

PS:这里再为大家推荐几款关于日期与时间计算的在线工具供大家参考使用:

在线日期/天数计算器:
http://tools.VeVB.COm/jisuanqi/date_jisuanqi

在线万年历日历:
http://tools.VeVB.COm/bianmin/wannianli

在线阴历/阳历转换工具:
http://tools.VeVB.COm/bianmin/yinli2yangli

Unix时间戳(timestamp)转换工具:
http://tools.VeVB.COm/code/unixtime

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android日期与时间操作技巧总结》、《Android开发入门与进阶教程》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结

希望本文所述对大家Android程序设计有所帮助。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表