UIDatePikcer的基本用法
- (void)viewDidLoad
{
[super viewDidLoad];
_datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 100, 320, 400)];
// 设置picker显示的样式
_datePicker.datePickerMode = UIDatePickerModeDate;
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor redColor];
btn.frame = CGRectMake(50, 420, 100, 50);
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
[self.view addSubview:_datePicker];
}
- (void)btnClick
{
NSDate *selDate = [_datePicker date];
// 时间格式器
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// 设置时间的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd / HH-mm"];
// 转换为字符串类型的对象
NSString *currentDate = [dateFormatter stringFromDate:selDate];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:currentDate delegate:Nil cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
[alertView show];
/*
yy: 年的后2位
yyyy: 完整年
MM: 月,显示为1-12
MMM: 月,显示为英文月份简写,如 Jan
MMMM: 月,显示为英文月份全称,如 Janualy
dd: 日,2位数表示,如02
d: 日,1-2位显示,如 2
EEE: 简写星期几,如Sun
EEEE: 全写星期几,如Sunday
aa: 上下午,AM/PM
H: 时,24小时制,0-23
K:时,12小时制,0-11
m: 分,1-2位
mm: 分,2位
s: 秒,1-2位
ss: 秒,2位
S: 毫秒
常用日期结构:
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd
MM dd yyyy
*/
}
UIDatePikcer的基本用法的更多相关文章
- EditText 基本用法
title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...
- jquery插件的用法之cookie 插件
一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...
- Java中的Socket的用法
Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...
- [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法
一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...
- python enumerate 用法
A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...
- [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...
- 【JavaScript】innerHTML、innerText和outerHTML的用法区别
用法: <div id="test"> <span style="color:red">test1</span> tes ...
- chattr用法
[root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...
- 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)
vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...
随机推荐
- c++ RTTI(runtime type info)
RTTI(Run-Time Type Information,通过运行时类型信息)程序能够使用基类的指针或引用来检查这些指针或引用所指的对象的实际派生类型. RTTI提供了以下两个非常有用的操作符: ...
- Node.js权威指南 (7) - 实现基于TCP与UDP的数据通信
7.1 使用net模块实现基于TCP的数据通信 / 136 7.1.1 创建TCP服务器 / 136 7.1.2 socket端口对象 / 142 7.1.3 创建TCP客户端 / 151 7.1.4 ...
- touchend事件的preventDefault阻止掉了click事件
<div id="box">box</div> <script> var isTouchDevice = function() { return ...
- android获取设备屏幕大小的方法
// 通过WindowManager获取 DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay( ...
- A configuration error occurred during startup. Please verify the preference field with the prompt: Cannot connect to vm
1.报错图 解决方法: Window->Preferences->MyEclipse Enterprice Workbench->Servers->Tomcat->选择你 ...
- leetcode 最大矩形和
1.枚举法(超时) public class Solution { public int largestRectangleArea(int[] height) { int max=-1; for(in ...
- poj 3465 Corn Fields 状态压缩
题目链接:http://poj.org/problem?id=3254 #include <cstdio> #include <cstring> #include <io ...
- openStack opts
- Installing scikit-learn
Installing scikit-learn http://scikit-learn.org/stable/install.html Installing scikit-learn There ar ...
- 平时Error记录
The Windows Firewall on this machine is currently 1.This row already belongs to another table. DataT ...