【065】◀▶ Android (II) - Java 等
●·● 目录:
A1 ………… Boolean 类
A2 ………… Byte 类
A3 ………… Integer 类
A4 ………… Float 类
A5 ………… String 类
A6 ………… Thread 类
A7 ………… System 类
A8 ………… ListView 类
D1 ………… AlertBuilder.Builder 类
DialogInterface 接口
DialogInterface.OnClickListener 接口
LayoutInflater 类
D2 ………… ProgressDialog 类
D3 ………… NotificationManager 类
D4 ………… Notification 类
D5 ………… PendingIntent 类
D6 ………… TimePickerDialog 类
D7 ………… DatePickerDialog 类
G1 ………… DecimalFormat 类
G2 ………… SimpleDateFormat 类
G3 ………… Date 类
G4 ………… Calendar 类
G5 ………… ProgressDialog 类
G6 ………… CheckBox 类
G7 ………… ProgressBar 类
G8 ………… ListView 类
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A1个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Boolean 类:
1. The wrapper for the primitive type boolean
.
2. Boolean Methods:
- toString(boolean value):返回值:static String. 将指定的布尔值转化为字符串.
- valueOf(String string):返回值:static Boolean. 将指定的字符串解析为 Boolean 对象.
- parseBoolean(String s):返回值:static boolean. 将指定的字符串转化为布尔值.
3. Boolean Fields:
- FALSE:false.
- TRUE:true.
- TYPE:Boolean 类.
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A2个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Byte 类:
1. The wrapper for the primitive type byte
.
2. Byte Methods:
- toString(byte value):返回值:static String. 将指定的 byte 值转化为字符串.
- shortValue():返回值:short. 将指定的 byte 值转化为 short.
- intValue():
- longValue():
- floatValue():
- doubleValue():
- byteValue():
- decode(String string):返回值:static Byte. 将指定的字符串解码成 Byte 实例, 前提是可以转.
- valueOf(String string):返回值:static Byte. 将指定的字符串解析为 Byte 对象.
- parseByte(String s):返回值:static byte. 将指定的字符串转化为 byte 值.
3. Byte Constants:
- MAX_VALUE:返回值:byte. Byte 的最大值, 27-1.
- MIN_VALUE:返回值:byte. Byte 的最小值, -27.
- SIZE:返回值:int. Byte 所占的位, 8.
System.out.println(Byte.decode("123")); //123 System.out.println(Byte.decode("077")); //63 System.out.println(Byte.decode("0x2F")); //47
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A3个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Integer 类:
1. The wrapper for the primitive type int
.
2. Byte Methods:
- toString(int int):返回值:static String. 将指定的 int 值转化为字符串.
- shortValue():返回值:short. 将指定的 byte 值转化为 short.
- intValue():
- longValue():
- floatValue():
- doubleValue():
- byteValue():
- decode(String string):返回值:static Integer. 将指定的字符串解码成 Integer 实例, 前提是可以转.
- valueOf(String string):返回值:static Integer. 将指定的字符串解析为 Integer 对象.
- parseInt(String s):返回值:static int. 将指定的字符串转化为 int 值.
- getInteger(String string):返回值:static Integer. 将指定的字符串解析为 Integer 对象.
- tobinaryString(int i):返回值:static String. 转为二进制文本.
- toHexString(int i):返回值:static String.转为十六进制文本.
- toOctalString(int i):返回值:static String.转为八进制文本.
3. Byte Constants:
- MAX_VALUE:返回值:int. Integer 的最大值, 231-1.
- MIN_VALUE:返回值:int. Integer 的最小值, -231.
- SIZE:返回值:int. Integer 所占的位, 32.
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A4个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Float 类:
1. The wrapper for the primitive type int
.
2. Float Constructs:
- Float(float value)
- Float(double value)
- Float(String string)
3. Byte Methods:
- toString(int int):返回值:static String. 将指定的 int 值转化为字符串.
- intValue():
- floatValue():
- doubleValue():
- longValue():
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A5个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● String 类:
1. The wrapper for the primitive type int
.
2. Byte Methods:
- indexOf(String):
- indexOf(String subString, int start):
- lastIndexOf(String):
- length():
- replace(CharSequence target, CharSequence replacement):
- replace(char oldChar, char newChar):
- substring(int start):
- substring(int start, int end):
- toCharArray():
- toUpperCase():
- trim():
- valueOf(double value):将其他的数据类型转为 String.(long, Object, int, float...)
- toLowerCase():
- startsWith(String prefix):
- endsWith(String suffix):
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A6个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Thread 类:
1. The wrapper for the primitive type int
.
2. Thread Constructors:
- Thread():构造一个没有 Runnable 对象并且新生成名称的线程.
- Thread(Runnable runnable):构造一个有 Runnable 对象并且新生成名称的线程.
举个例子new Thread(new Runnable(){ public void run(){ for (int i=1; i<=15; i++) { try { //---simulate doing something lengthy--- Thread.sleep(1000); //---update the dialog--- progressDialog.incrementProgressBy((int)(100/15)); } catch (InterruptedException e) { e.printStackTrace(); } } progressDialog.dismiss(); } }).start();
- Thread(Runnable runnable, String threadName):构造一个有 Runnable 对象并且指定名称的线程.
- Thread(String threadName):构造一个没有 Runnable 对象但是有指定名称的线程.
3. Thread Methods:
- activeCount():返回值:static int. 返回激活进程的个数.
- currentThread():返回值:static Thread. 返回当前的进程.
- sleep(long millis):返回值:static void. 休眠指定的时间.
- start():开始执行线程.
- suspend():不推荐.
- stop():不推荐.
- getId():返回值:long. 返回线程的 Id.
- getName():返回值:String. 返回线程的名称.
- getPriority():返回值:int. 返回线程的优先级.
- isAlive():返回值:boolean. 返回线程是否还在运行.
- run():
- setName(String threadName):
- setPriority(int priority):
- notify():
- notifyAll():
- wait():
- wait(long millis):
4. Thread Constants:
- MAX_PRIORITY:对于一个线程的最大优先级值.
- MIN_PRIORITY:对于一个线程的最小优先级值.
- NORM_PRIORITY:给线程分配的默认优先级值.
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第A7个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● System 类:
1. Provides access to system-related information and resources including standard input and output.
2. System Methods:
- currentTimeMillis():返回值:static long. 返回当前系统时间的微秒值, 从 1970.1.1 00:00:00 UTC 算起.
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第D1个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● AlertDialog.Builder 类:
1. 构造一个 AlertDialog, 是 AlertDialog 的嵌套类.
2. AlertDialog.Builder Methods:
- setTitle(CharSequence title):标题内容.
- setTitle(int titleId):
- setIcon(int iconId):在标题左边上图标.
- setTitle(Drawable icon):
- setTitle(int messageId):显示的信息内容.
- setTitle(CharSequence message):
- setCancelable(boolean cancelable):是否可以通过返回按钮撤销弹出框.
- setPositiveButton(int textId, DialogInterface.OnClickListener listener):设置"确定"按钮, 及其点击事件.
- setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener):
- setNeutralButton(int textId, DialogInterface.OnClickListener listener):设置"中间"按钮, 及其点击事件.
- setNeutralButton(CharSequence text, DialogInterface.OnClickListener listener):
- setNegativeButton(int textId, DialogInterface.OnClickListener listener):设置"取消"按钮, 及其点击事件.
- setNegativeButton(CharSequence text, DialogInterface.OnClickListener listener):
- setOnCancelListener(DialogInterface.OnCancelListener onCancelListener):当执行 cancel() 时触发的事件.
- setSingleChoiceItems(CharSequence[] items, int checkedItem, DialogInterface.OnClickListener listener):在对话框中设置 list, 同时包含单选按钮.
- setSingleChoiceItems(ListAdapter adapter, int checkedItem, DialogInterface.OnClickListener listener):
- setSingleChoiceItems(int itemsId, int checkedItem, DialogInterface.OnClickListener listener):
- setSingleChoiceItems(Cursor cursor, int checkedItem, String labelColumn, DialogInterface.OnClickListener listener):
- setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener):
在对话框中设置 list, 同时包含复选按钮.
第一个参数:显示的每一个条目. eg: CharSequence[] items = { "Google", "Apple", "Microsoft" };
第二个参数:每个条目对应的布尔值, 是否选中复选框. eg: boolean[] itemsChecked = new boolean [items.length]; (默认都为false)
第三个参数:条目被点击的时候触发的事件.
一连串的实现方法, 没有命名新的实例protected Dialog onCreateDialog1() { return new AlertDialog.Builder(this) .setIcon(R.drawable.ic_launcher) .setTitle("This is a dialog with some simple text...") .setMultiChoiceItems(items, itemsChecked, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean isChecked) { Toast.makeText(getBaseContext(), items[which] + (isChecked ? " checked!":" unchecked!"), Toast.LENGTH_SHORT).show(); } } ).create(); }
- setMultiChoiceItems(Cursor cursor, String isCheckedColumn, String labelColumn, DialogInterface.OnMultiChoiceClickListener listener):
- setMultiChoiceItems(int itemsId, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener listener):
- setItems(int itemsId, DialogInterface.OnClickListener listener):在对话框中设置 list.
- setItems(CharSequence[] items, DialogInterface.OnClickListener listener):局部变量要用 final.
- setView(View view):
- setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener):
- setOnKeyListener(DialogInterface.OnKeyListener onKeyListener):
- setAdapter(ListAdapter adapter, DialogInterface.OnClickListener listener):
- getContext():获取对应 context.
- create():返回值:AlertDialog. 创建.
- show():返回值:AlertDialog. 显示.
※ 参考:Android 对话框(Dialog)大全 建立你自己的对话框
●·● DialogInterface 接口:对话框接口, 包括下面的嵌套类.
来源:android.content.DialogInterface
- cancel():取消对话框.
- dismiss():取消对话框.(功能差不多, 不同在于不能接受取消的事件)
●·● DialogInterface.OnClickListener 类:对话框中的按钮被点击的处理事件.
- onClick(DialogInterface dialog, int which):当按钮被点击的时候将会唤醒. dialog 表示对话框, which 表示 Items 中索引.
☀☀☀<< 举例 >>☀☀☀
效果:
点击按钮实现 & 对话框方法:
public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { //点击"返回键"时触发. dialog(); } return false; }
protected void dialog(){ AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("请输入"); //标题 builder.setIcon(android.R.drawable.ic_dialog_info); //图标 builder.setView(new EditText(MainActivity.this)); //TextView builder.setPositiveButton("Yes", null); //Yes builder.setNegativeButton("No", null); //No builder.create().show(); }
效果:
XML: dialog.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/dialog" android:layout_width="wrap_content" android:layout_height="match_parent" > <EditText android:layout_height="wrap_content" android:layout_width="165dip" android:id="@+id/etname" android:layout_marginRight="20dip" android:layout_alignParentRight="true" android:minWidth="100dip"/> <TextView android:layout_height="wrap_content" android:layout_width="80dip" android:textColor="#fff" android:textSize="20sp" android:layout_marginLeft="20dip" android:layout_alignBaseline="@id/etname" android:id="@+id/tvname" android:text="账号:" /> <EditText android:layout_height="wrap_content" android:layout_width="165dip" android:password="true" android:layout_marginRight="20dip" android:layout_below="@id/etname" android:layout_alignLeft="@id/etname" android:layout_alignParentRight="true" android:id="@+id/etname2" android:minWidth="100dip"/> <TextView android:layout_height="wrap_content" android:layout_width="80dip" android:textColor="#fff" android:textSize="20sp" android:layout_alignBaseline="@id/etname2" android:layout_alignLeft="@id/tvname" android:id="@+id/tvname2" android:text="密码:" /> <LinearLayout android:orientation="horizontal" android:layout_centerHorizontal="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/etname2" > <CheckBox android:id="@+id/checkBox1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#fff" android:layout_marginRight="20dip" android:checked="true" android:text="记住密码" /> <CheckBox android:id="@+id/checkBox2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#fff" android:text="自动登录" /> </LinearLayout> </RelativeLayout>
Java:
protected void dialogItem(){ AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.dialog, (ViewGroup)findViewById(R.id.dialog)); builder.setTitle("账号登陆"); builder.setIcon(android.R.drawable.ic_menu_compass); //添加系统自带图标 builder.setView(layout); //添加布局 builder.setPositiveButton("登录", null); builder.setNegativeButton("取消", null); builder.create().show(); }
●·● LayoutInflater 类:将一个 XML 文件的布局转化成 View 对象.
来源:android.view.LayoutInflater
- inflate(int resource, ViewGroup root):返回值:View. 通过 xml 文件及布局转换为 View.
- inflate(XmlPullParser parser, ViewGroup root):
- inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot):
- inflate(int resource, ViewGroup root, boolean attachToRoot):
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第D2个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● ProgressDialog 类:
1. 带进度条的对话框, 创建实例可以返回 static ProgressDialog 的 show 方法实现.
2. ProgressDialog Methods:
- getMax():获取进度条的最大进度.
- getProgress():获取进度条的进度.
- getSecondaryProgress():获取第二进度条的进度.
- incrementProgressBy(int diff):进度条进度的增加量.
进度随时间逐渐增加new Thread(new Runnable(){ public void run(){ for (int i=1; i<=15; i++) { try { //---simulate doing something lengthy--- Thread.sleep(1000); //---update the dialog--- progressDialog.incrementProgressBy((int)(100/15)); } catch (InterruptedException e) { e.printStackTrace(); } } progressDialog.dismiss(); } }).start();
- incrementSecondaryProgressBy(int diff):第二进度条进度的增加量.
- onStart():
- dismiss():关掉对话框.
- setMax(int max):设置进度条的最大进度.
- setMessage(CharSequence message):
- setProgress(int value):设置进度条的进度.
- setProgressStyle(int style):设置进度条的样式.
STYLE_HORIZONTAL:水平进度条.
STYLE_SPINNER:旋转进度条. - setSecondaryProgress(int secondaryProgress):设置第二进度条的进度.
- setButton(CharSequence text, Message msg):废弃了.
- setButton(CharSequence text, DialogInterface.OnClickListener listener):废弃了.
- setButton(int whichButton, CharSequence text, Message msg)
第一个参数:从下面三个常量中选择.
BUTTON_NEGATIVE
BUTTON_NEUTRAL
BUTTON_POSITIVE
第二个参数:按钮上面显示的文本.
第三个参数:按钮点击的时候, message 被发送. - setButton(int whichButton, CharSequence text, DialogInterface.OnClickListener listener)
第三个参数:按钮的点击事件. - show():此方法非静态, 其他的重载方法都是静态的~
- show(Context context, CharSequence title, CharSequence message):返回值:static ProgressDialog.
第一个参数:activity.
第二个参数:进度对话框显示的标题. (蓝色字)
第三个参数:进度对话框进度条旁边显示的内容. (白色字)
- show(Context context, CharSequence title, CharSequence message, boolean indeterminate):
第四个参数:若为 true, 则进度条不确定地从左向右滚动.
※ 参考:http://zhidao.baidu.com/question/307371372.html
- show(Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable):
第五个参数:是否可以中途取消此进度框. - show(Context context, CharSequence title, CharSequence message, boolean indeterminate, boolean cancelable, DialogInterface.OnCancelListener cancelListener):
第六个参数:当中途取消此进度框的时候触发的事件.
实现六个参数的进度款显示, 线程睡眠 10 秒钟public void onClick2(View v) { //---show the dialog--- final ProgressDialog dialog = ProgressDialog.show( this, "Doing something", "Please wait...", true , true, new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { // TODO Auto-generated method stub Toast.makeText(DialogActivity.this, "gaha", Toast.LENGTH_SHORT).show(); } }); new Thread(new Runnable(){ public void run(){ try { //---simulate doing something lengthy--- Thread.sleep(10000); //---dismiss the dialog--- dialog.dismiss(); } catch (InterruptedException e) { e.printStackTrace(); } } }).start(); }
※ 参考:Android学习笔记之ProgressDialog
※ 参考:android.Dialogs
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第D3个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● NotificationManager 类:
1. Class to notify the user of events that happen. This is how you tell the user that something has happened in the background.
2. NotificationManager Constructors:
- 通过 activity 的 getSystemService(String name) 方法获取.
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
3. NotificationManager Methods:
- cancel(int id):取消之前显示的通知.
参数:下面发布通知时候对应的通知 ID. - cancel(String tag, int id):
- cancelAll():取消之前显示的所有通知.
- notify(int id, Notification notification):发布一条通知并显示到状态栏上.
第一个参数:通知 ID, 用于后面取消通知使用.
第二个参数:通知. - notify(String tag, Int id, Notification notification):
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第D4个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Notification 类:
1. A class that represents how a persistent notification is to be presented to the user using the NotificationManager
.
2. Notification Constructors:
- Notification():
- Notification(int icon, CharSequence tickerText, long when):
第一个参数:图标.
第二个参数:显示文本.
第三个参数:什么时候显示. - Notification(Parcel parcel):
3. Notification Methods:
- setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent):
第一个参数:activity.
第二个参数:标题内容.
第三个参数:消息内容.
第四个参数:
4. Notification Fields:
- vibrate:返回值:long[].
notif.vibrate = new long[] { 100, 250, 100, 500};
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第D5个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● PendingIntent 类:
1. A description of an Intent and target action to perform with it.
2. PendingIntent Methods:
- getActivities(Context context, int requestCode, Intent[] intents, int flags):返回值:static PendingIntent.
- getActivities(Context context, int requestCode, Intent[] intents, int flags, Bundle options):返回值:static PendingIntent.
- getActivity(Context context, int requestCode, Intent intent, int flags):返回值:static PendingIntent.
第一个参数:activity.
第二个参数:请求码, 常量. (貌似没什么用)
第三个参数:被执行 activity 的 intent.
第四个参数: - getActivity(Context context, int requestCode, Intent intent, int flags, Bundle options):返回值:static PendingIntent.
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第D6个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● TimePickerDialog 类:
1. A dialog that prompts the user for the time of day using a TimePicker
.
2. TimePickerDialog Constructors:
- TimePickerDialog(Context context, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView):
第一个参数:Parent.
第二个参数:要在内部实现下面的方法, 在内部可以将设置的小时和分钟等数据传递给变量.
onTimeSet(TimePicker view, int hourOfDay, int minute):必须实现的方法.
第一个参数:显示的 Timepicker.
第二个参数:设置的小时数.
第三个参数:设置的分钟数.
第三个参数:初始化的小时值.
第四个参数:初始化的分钟值.
第五个参数:是否为24小时制, 否则为AM/PM制. - TimePickerDialog(Context context, int theme, TimePickerDialog.OnTimeSetListener callBack, int hourOfDay, int minute, boolean is24HourView):
TimePickerDialog timePickerDialog = new TimePickerDialog( this, new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minuteOfHour) { // TODO Auto-generated method stub yr = view.getCurrentHour(); month = view.getCurrentMinute(); hour = hourOfDay; minute = minuteOfHour; SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm aa"); Date date = new Date(0,0,0, hour, minute); String strDate = timeFormat.format(date); Toast.makeText(getBaseContext(),"You have selected " + strDate, Toast.LENGTH_SHORT).show(); } }, 10, 10, true);
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第D6个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● DatePickerDialog 类:
1. A simple dialog containing an DatePicker
.
2. DatePickerDialog Constructors:
- DatePickerDialog(Context context, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth):
- DatePickerDialog(Context context, int theme, DatePickerDialog.OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth):
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第G1个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● DecimalFormat 类:
1. 小数格式.
2. DecimalFormat Constructors:
- DecimalFormat():
- DecimalFormat(String pattern):初始化指定样式的小数格式.
- DecimalFormat(String pattern, DecimalFormatSymbols value):
3. DecimalFormat Methods:
- applyPattern(String pattern):应用样式.
- format(double value):返回值:String. 返回指定样式的字符串.(用于输出)
- format(long value):返回值:String. 返回指定样式的字符串.(用于输出)
※ 参考:DecimalFormat的用法
※ 参考:DecimalFormat的用法介绍
Symbol | Location | Localized? | Meaning |
---|---|---|---|
0 |
Number | Yes | 数字. |
@ |
Number | No | 有效数字. |
# |
Number | Yes | 数字, 前面的 0 不显示. |
. |
Number | Yes | 小数分隔符. |
- |
Number | Yes | 负号. |
, |
Number | Yes | 分组符, 逗号. |
E |
Number | Yes | 科学技术法, 指数. |
+ |
Exponent | Yes | 正号. |
; |
Subpattern boundary | Yes | 分隔正数和负数子模式. |
% |
Prefix or suffix | Yes | 乘以 100 并显示为百分数. |
‰ (\u2030 ) |
Prefix or suffix | Yes | 乘以 1000 并显示为千分数. |
¤ (\u00A4 ) |
Prefix or suffix | No | 货币记号,由货币符号替换。如果两个同时出现,则用国际货币符号替换。如果出现在某个模式中,则使用货币小数分隔符,而不使用小数分隔符。 |
' |
Prefix or suffix | No | 用于在前缀或或后缀中为特殊字符加引号,例如 "'#'#" 将 123 格式化为 "#123" 。要创建单引号本身,请连续使用两个单引号:"# o''clock" 。 |
* |
Prefix or suffix boundary | Yes | NEW Pad escape, precedes pad character. |
有效数字显示, 最小的有效数字个数用'@'表示, 最大的有效数字个数用'@'和'#'的和来表示
Pattern | Minimum significant digits | Maximum significant digits | Number | Output of format() |
---|---|---|---|---|
@@@ |
3 | 3 | 12345 | 12300 |
@@@ |
3 | 3 | 0.12345 | 0.123 |
@@## |
2 | 4 | 3.14159 | 3.142 |
@@## |
2 | 4 | 1.23004 | 1.23 |
pattern | value | Output of format() |
0.0 | 1234.5678 | 1234.6 |
00000.000 kg | 1234.5678 | 01234.568 kg |
##000.000 kg | 1234.5678 | 1234.568 kg |
-000.000 | 1234.5678 | -1234.568 |
-0,000.0# | 1234.5678 | -1,234.57 |
0.00E000 | 1234.5678 | 1.23E003 |
0.00% | 1234.5678 | 123456.79% |
0.00/u2030 | 1234.5678 | 1234567.89‰ |
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第G2个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● SimpleDateFormat 类:
1. 简单的日期格式. 将日期转换为 String 类型.
2. SimpleDateFormat Constructors:
- SimpleDateFormat()
- SimpleDateFormat(String pattern)
样式可以自己写进去
yy:年(两位)
yyyy:年(四位)
MM:月份
dd:日期
hh, HH:小时
mm:分钟
ss
aa:AM & PM
yyyy-MM-dd 1970-01-01 yyyy-MM-dd HH:mm 1970-01-01 00:00 yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000
3. SimpleDateFormat Methods:
- format(Date date):以预设的模式显示成文本.
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第G2个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Date 类:
1. 日期.
2. Date Constructors:
- Date()
- Date(int year, int month, int day):month 从 0 开始的~
- Date(int year, int month, int day, int hour, int minute)
- Date(int year, int month, int day, int hour, int minute, int second)
- Date(long milliseconds)
- Date(String string)
---------------------------------------------------------------------------------------------------------
╔════════╗
╠════╣ 第G3个 ╠══════════════════════════════════════════════════╣
╚════════╝
●·● Calendar 类:
1. 日历.
Calendar rightNow = Calendar.getInstance()
2. Calendar Methods:
- get(int field):返回值:int. 获取指定的值. 传递的参数为下面的常量.
3. Calendar Constants:
- DAY_OF_MONTH:
- DAY_OF_WEEK:
- DAY_OF_WEEK_IN_MONTH:
- DAY_OF_YEAR:
- HOUR_OF_DAY:
- MONTH:
- WEEK_OF_MONTH:
- WEEK_OF_YEAR:
- YEAR: