Timeクラス

android.text.formatTimeクラス

Time

 状態:-  閲覧数:1,792  投稿日:2014-02-22  更新日:2014-02-22  
・日付を操作するクラス

クラス構成

 閲覧数:377 投稿日:2014-02-22 更新日:2014-02-22 

親クラス



java.lang.Object
  ↳ android.text.format.Time



コード例

 閲覧数:432 投稿日:2014-02-23 更新日:2014-02-23 

例1


現在日時を表示
・テキストビューを使って、文字を表示

▼/Time/src/android/style/TimeActivity.java
package android.style;

import java.text.TimeFormat;
import java.text.ParseException;
import java.text.SimpleTimeFormat;
import java.util.Calendar;
import java.util.Time;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.format.TimeUtils;
import android.text.format.Time;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TimePicker;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TimeActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

sample1();

public void printString(String s) {
// ベースのレイアウト取得
LinearLayout parent = (LinearLayout) findViewById(R.id.parent);
TextView tv = new TextView(this);
tv.setTypeface(Typeface.MONOSPACE); // 等幅フォントの指定
tv.setText(s);
parent.addView(tv); // ビューの追加
}

public void sample3() {

// android.text.format.Timeクラスでの現在日時
Time time = new Time();// Timeクラスのコンストラクタには、引数として任意のタイムゾーンを指定することができる。何も指定しない場合は、デフォルトのタイムゾーンとなる
time.setToNow();// Timeオブジェクトに現在日時を設定
String tmp = time.year + "/" + (time.month + 1) + "/" + time.monthDay
+ " " + time.hour + ":" + time.minute + ":" + time.second;
printString(tmp);

// タイムゾーンの表示
printString(Time.getCurrentTimezone());// Time.getCurrentTimezoneメソッド … 引数現在のタイムゾーンを示す文字列を返す
}
}


・xml … レイアウト
▼/res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:id="@+id/parent"
   >
</LinearLayout>



コメント投稿(ログインが必要)



類似度ページランキング
順位 ページタイトル抜粋
1 Timeクラス 100
2 Viewクラス 71
3 TextViewクラス 67
4 EditTextクラス 67
5 Threadクラス 63
6 Dateクラス 57
7 TableRowクラス 56
8 ListViewクラス 56
9 Fragmentクラス 56
10 CardViewクラス 56
11 Rクラス 55
12 Toastクラス 53
13 ViewGroupクラス 53
14 DateUtilsクラス 53
15 抽象クラス 50
16 Bundleクラス 50
17 ScrollViewクラス 50
18 TableLayoutクラス 48
19 FrameLayoutクラス 48
20 AlertDialogクラス 48
2024/9/21 20:36 更新