Android Studio 中获取时间

Android Studio 中获取时间,第1张

概述AndroidStudio中获取时间先把这个包导入importjava.text.SimpleDateFormat;然后自己定义一个TextView,我的叫current_timepublicclassresultActivityextendsAppCompatActivity{privateTextViewmTextView,current_time;@Overrideprotectedvoido AndroID Studio 中获取时间

先把这个包导入import java.text.SimpleDateFormat;
然后自己定义一个TextVIEw,我的叫current_time

public class resultActivity extends AppCompatActivity {    private TextVIEw mTextVIEw,current_time;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_result);        current_time = findVIEwByID(R.ID.current_time);        SimpleDateFormat   formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        Date curDate =  new Date(System.currentTimeMillis());        //获取当前时间        String  str =  formatter.format(curDate);        current_time.setText(str);    }
SimpleDateFormat   formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

这句话是可以按自己需求修改的,比如自己不想要后面的秒,就把ss删去

这些代码写上去就可以获取当前时间了

总结

以上是内存溢出为你收集整理的Android Studio 中获取时间全部内容,希望文章能够帮你解决Android Studio 中获取时间所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1037140.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-24
下一篇2022-05-24

发表评论

登录后才能评论

评论列表(0条)

    保存