2012年12月27日 星期四

Local datetime in SQLite




This article shows how to get the local date time from SQLite


When we run the following SQL, it returns the UTC time..

select datetime('now');

2012-12-26 16:01:07




To return the local time, you can add the the parameter 'localtime' 

select datetime('now', 'localtime');

2012-12-27 00:01:07

2012年12月18日 星期二

[How-to] Get the year-month-day (yyyy-mm-dd) from a date field in SQLite

SQLite is the database for the Android Application.


The following SQL is an example of getting date by SQL statement.

select _id, strftime('%Y-%m-%d', create_date) c_date from TABLE1

Returned result:


Another SQL example shows how to get counts of records by date

select strftime('%Y-%m-%d', create_date), count(strftime('%Y-%m-%d', create_date) ) from TABLE1 group by strftime('%Y-%m-%d', create_date)



More reference for the date field in SQLite can be found in the official website
http://www.sqlite.org/lang_datefunc.html

2012年12月11日 星期二

[Resolved] Android: WebView Web Page not available

Today I'm trying to create a WebView in Android, it shows a Web page not available after running the app in the emulator.




       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
             
              WebView wv = (WebView) findViewById(R.id.webView1);             
              wv.loadUrl("https://www.google.com");
             
                }

Solution 

1. Make sure the permission is granted
<uses-permission android:name="android.permission.INTERNET"></uses-permission>


2. Make sure the following bold content in your code
       protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
             
              WebView wv = (WebView) findViewById(R.id.webView1);
              wv.setWebViewClient(new WebViewClient(){});
             
              wv.loadUrl("https://www.google.com");
             
                }