如何插入从Android应用程序源码中的当前日期 [英] How to insert current date in sqlite from android application

查看:104
本文介绍了如何插入从Android应用程序源码中的当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要插入的SQLite数据库的datetime类型字段当前日期。
我怎样才能做到这一点?

I want to insert current date in SQLite database datetime type field. How can I do this?

更新:使用 mDb.execSQL(插入+ DATABASE_TABLE +VALUES(DATETIME()));

我能够像插入 = DATE_CREATED 2012年10月10日13时02分08秒,我想这种格式 2012年10月10日12: 48 如何才达到这一点?

I am able to insert like date_created=2012-10-10 13:02:08 and I want this format 10 Oct 2012 12:48 how to achive this?

推荐答案

我preFER通过以下方式来完成它:

I prefer the following ways to get it done:


  1. 创建一个具有默认设置表把当前日期时间
    自动。例如:

  1. Create the table with a default settings to put current datetime automatically. For example:

ColumnName DATETIME DEFAULT CURRENT_TIMESTAMP


  • 创建的SimpleDateFormat 和电流转换成日期格式的SQL
    串。例如:

  • Create SimpleDateFormat and convert current date into SQL format string. For example:

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String strDate = sdf.format(new Date());
    
    ContentValues values = new ContentValues();
    values.put("ColumnName", strDate);
    


  • 这篇关于如何插入从Android应用程序源码中的当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆