JAVA中如何获取毫秒和微秒数

JAVA中如何获取毫秒和微秒数,第1张

一、获取毫秒数的代码:

(1)SystemcurrentTimeMillis() 这种方式速度最快。

(2)CalendargetInstance()getTimeInMillis() 这种方式速度最慢。

二、获取微秒数的代码:

微秒使用SystemnanoTime()方法:如果Java程序需要高精度的计时,如1毫秒或者更小,使用SystemnanoTime()方法,可以满足需求。

扩展资料:

获取微秒函数SystemnanoTime() 的隐患:

SystemcurrentTimeMillis() 起始时间是基于 197011 0:00:00 这个确定的时间的,而SystemnanoTime()是基于cpu核心的时钟周期来计时,它的开始时间是不确定的。

但是在多核处理器上,由于每个核心的开始时间不确定,那么

“long start = SystemnanoTime();String ip = UtilitiesgetIpByUrl(url);long cost = SystemnanoTime() - start;  ”

这段代码有可能会运行在两个不同的cpu核心上,从而导致得到的结果完全不符逻辑。

1、统一收键盘的方法

[[[UIApplication sharedApplication] keyWindow] endEditing:YES];

2、提示框

BBAlertView alert = [[BBAlertView alloc] initWithStyle:BBAlertViewStyleDefault

Title:@"删除订单"

message:@"是否删除订单,"

customView:nil

delegate:self

cancelButtonTitle:L(@"取消")

otherButtonTitles:L(@"确认")];

[alert setCancelBlock:^{

}];

[alert setConfirmBlock:^{

[self orderDidRemovePressDown:tempDic Index:indexsection];

}];

[alert show];

3、的自适应功能

selfbrandImagecontentMode = UIViewContentModeScaleAspectFit;

4、cocoaPods清除缓存问题

$ sudo rm -fr ~/cocoapods/repos/master

$ pod setup

5、设置显示键盘的样式

textViewkeyboardType =UIKeyboardTypeDefault;

//设置键盘右下角为完成(中文输入法下)

textViewreturnKeyType=UIReturnKeyDone;

6、输出当前时间

NSDateFormatter dateFormatter=[[NSDateFormatter alloc]init];

[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ssSSS"];

NSLog(@"当前毫秒时间1==%@",[dateFormatter stringFromDate:[NSDate date]]);

7、显示两秒然后消失

UILabel lab=[[UILabel alloc]initWithFrame:CGRectMake(60,Main_Screen_Height-64-49-60, Main_Screen_Width-120, 50)];

labbackgroundColor=[UIColor grayColor];

ViewRadius(lab, 20);

labtextAlignment=NSTextAlignmentCenter;

labtext=@"请先进行实名制验证";

[selfview addSubview:lab];

[UILabel animateWithDuration:2 animations:^{

labalpha=0;

}completion:^(BOOL finished) {

[lab removeFromSuperview];

}];

8、设置placeholder属性的大小和颜色

[_phoneFie setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabeltextColor"];

[_phoneFie setValue:[UIFont boldSystemFontOfSize:15] forKeyPath:@"_placeholderLabelfont"];

_phoneFiereturnKeyType=UIReturnKeyDone;

9、设置cell的交互完全不可以使用

//[cellTwo setUserInteractionEnabled:NO];

//设置cell不可以点击,但是上面的子控件可以交互

cellTwoselectionStyle=UITableViewCellSelectionStyleNone;

10、将textField的placeholder 属性的字体向右边移动5

_fieldleftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10Width_375, _fieldframesizeheight)];

_fieldleftViewMode = UITextFieldViewModeAlways;

11、开新线程使按钮上的时间变化

-(void)startTime{

__block int timeout=60; //倒计时时间

UIButton btn=(UIButton )[selfview viewWithTag:1000];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);

dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),10NSEC_PER_SEC, 0); //每秒执行

dispatch_source_set_event_handler(_timer, ^{

if(timeout<=0){

dispatch_source_cancel(_timer);

dispatch_async(dispatch_get_main_queue(), ^{

[btn setTitle:@"发送验证码" forState:UIControlStateNormal];

btnenabled = YES;

});

}else{

//  int minutes = timeout / 60;

int miao = timeout % 60;

if (miao==0) {

miao = 60;

}

NSString strTime = [NSString stringWithFormat:@"%2d", miao];

dispatch_async(dispatch_get_main_queue(), ^{

[btn setTitle:[NSString stringWithFormat:@"剩余%@秒",strTime] forState:UIControlStateNormal];

btnenabled = NO;

});

timeout--;

}

});

dispatch_resume(_timer);

}

12、隐藏TableView 中多余的行

UIView view=[[UIView alloc]initWithFrame:CGRectZero];

[_tabelView setTableFooterView:view];

13、UIView添加背景

UIImage image=[UIImage imageNamed:@"friend750"];

headSeVlayercontents=(id)imageCGImage;

14、UITableView取消选中状态

[tableView deselectRowAtIndexPath:indexPath animated:YES];// 取消选中

15、带属性的字符串

NSFontAttributeName  字体

NSParagraphStyleAttributeName  段落格式

NSForegroundColorAttributeName  字体颜色

NSBackgroundColorAttributeName  背景颜色

NSStrikethroughStyleAttributeName 删除线格式

NSUnderlineStyleAttributeName      下划线格式

NSStrokeColorAttributeName        删除线颜色

NSStrokeWidthAttributeName 删除线宽度

NSShadowAttributeName  阴影

1  使用实例

UILabel testLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 320, 30)];

testLabelbackgroundColor = [UIColor lightGrayColor];

testLabeltextAlignment = NSTextAlignmentCenter;

NSMutableAttributedString AttributedStr = [[NSMutableAttributedString alloc]initWithString:@"今天天气不错呀"];

[AttributedStr addAttribute:NSFontAttributeName

value:[UIFont systemFontOfSize:160]

range:NSMakeRange(2, 2)];

[AttributedStr addAttribute:NSForegroundColorAttributeName

value:[UIColor redColor]

range:NSMakeRange(2, 2)];

testLabelattributedText = AttributedStr;

[selfview addSubview:testLabel];

16、加大按钮的点击范围

把UIButton的frame 设置的大一些,然后给UIButton设置一个小些的

[tmpBtn setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];

// 注意这里不能用setBackgroundImage

[tmpBtn setImage:[UIImage imageNamed:@"testBtnImage"] forState:UIControlStateNormal];

17、//避免self的强引用

__weak ViewController weakSelf = self;

18、//类别的创建

command +n ——>Objective-C File———>(File Type  选择是类别还是扩展)———>(Class  选择为哪个控件写类别)

19、修改UITableview 滚动条颜色的方法

selftableViewindicatorStyle=UIScrollViewIndicatorStyleWhite;

20、利用UIWebView显示pdf文件

webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];

[webView setDelegate:self];

[webView setScalesPageToFit:YES];

[webViewsetAutoresizingMask:UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight];

[webView setAllowsInlineMediaPlayback:YES];

[selfview addSubview:webView];

NSString pdfPath = [[NSBundle mainBundle]pathForResource:@"ojc" ofType:@"pdf"];

NSURL url = [NSURLfileURLWithPath:pdfPath];

NSURLRequest request = [NSURLRequestrequestWithURL:url

cachePolicy:NSURLRequestUseProtocolCachePolicy

timeoutInterval:5];

[webView loadRequest:request];

21、将plist文件中的数据赋给数组

NSString thePath = [[NSBundle mainBundle]pathForResource:@"States" ofType:@"plist"];

NSArray array = [NSArrayarrayWithContentsOfFile:thePath];

22、隐藏状态栏

[[UIApplication shareApplication]setStatusBarHidden: YES animated:NO];

23、给navigation  Bar  设置title颜色

UIColor whiteColor = [UIColor whiteColor];

NSDictionary dic = [NSDictionary dictionaryWithObject:whiteColor forKey:NSForegroundColorAttributeName];

[selfnavigationControllernavigationBar setTitleTextAttributes:dic];

24、使用AirDrop 进行分享

NSArray array = @[@"test1", @"test2"];

UIActivityViewController activityVC = [[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];

[self presentViewController:activityVC animated:YES

completion:^{

NSLog(@"Air");

}];

25、把tableview里面Cell的小对勾的颜色改成别的颜色

_mTableViewtintColor = [UIColor redColor];

26、UITableView去掉分割线

_tableViewseparatorStyle = NO;

27、正则判断手机号码地址格式

- (BOOL)isMobileNumber:(NSString )mobileNum {

//    电信号段:133/153/180/181/189/177

//    联通号段:130/131/132/155/156/185/186/145/176

//    移动号段:134/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178

//    虚拟运营商:170

NSString MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$";

NSPredicate regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];

return [regextestmobile evaluateWithObject:mobileNum];

}

28、控制交易密码位数

-(BOOL)textField:(UITextField )textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString )string{

if (textFieldtextlength >=6){

[MBProgressHUD showMessage:@"密码为6位" afterDelay:18];

return NO;

}

return YES;

}

29、判断是不是空

if ([real_name isKindOfClass:[NSNull class]] ) {

return NO;}

30、点击号码拨打电话

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://400966220"]];

31、控制UITabbar的选择哪一个

[selftabBarController setSelectedIndex:1];

32、获取当前App的版本号

NSDictionary infoDictionary = [[NSBundle mainBundle] infoDictionary];

CFShow(infoDictionary);

// app名称

NSString app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];

// app版本

NSString app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

// app build版本

NSString app_build = [infoDictionary objectForKey:@"CFBundleVersion"];

33、苹果app权限NSPhotoLibraryUsageDescriptionApp需要您的同意,才能访问相册NSCameraUsageDescriptionApp需要您的同意,才能访问相机NSMicrophoneUsageDescriptionApp需要您的同意,才能访问麦克风NSLocationUsageDescriptionApp需要您的同意,才能访问位置NSLocationWhenInUseUsageDescriptionApp需要您的同意,才能在使用期间访问位置NSLocationAlwaysUsageDescriptionApp需要您的同意,才能始终访问位置NSCalendarsUsageDescriptionApp需要您的同意,才能访问日历NSRemindersUsageDescriptionApp需要您的同意,才能访问提醒事项NSMotionUsageDescriptionApp需要您的同意,才能访问运动与健身NSHealthUpdateUsageDescriptionApp需要您的同意,才能访问健康更新NSHealthShareUsageDescriptionApp需要您的同意,才能访问健康分享NSBluetoothPeripheralUsageDescriptionApp需要您的同意,才能访问蓝牙NSAppleMusicUsageDescriptionApp需要您的同意,才能访问媒体资料库

34、控件设置边框

_describTextlayerborderColor = [[UIColor colorWithRed:2150 / 2550 green:2150 / 2550 blue:2150 / 2550 alpha:1] CGColor];

_describTextlayerborderWidth = 10;

_describTextlayercornerRadius = 40;

_describTextclipsToBounds = YES;

35、//隐藏电池条的方法

-(BOOL)prefersStatusBarHidden{

return YES;

}

36、延时 *** 作

[NSThread sleepForTimeInterval:2];

方法二:

[self performSelector:@selector(delayMethod) withObject:nil afterDelay:15];

37、系统风火轮:

[UIApplication sharedApplication]networkActivityIndicatorVisible = NO; //隐藏

38、//didSelectRowAtIndexPath:方法里面找到当前的Cell

AssessMentCell cell = [tableView cellForRowAtIndexPath:indexPath];

39、navigation上返回按钮的颜色以及返回按钮后面文字去掉

//返回按钮后边文字去掉

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)

forBarMetrics:UIBarMetricsDefault];

//设置左上角返回按钮的颜色

selfnavigationControllernavigationBartintColor = UIColorFromRGB(0x666666);

40、lineBreakMode //设置文字过长时的显示格式

labellineBreakMode = NSLineBreakByCharWrapping;以字符为显示单位显

示,后面部分省略不显示。

labellineBreakMode = NSLineBreakByClipping;剪切与文本宽度相同的内

容长度,后半部分被删除。

labellineBreakMode = NSLineBreakByTruncatingHead;前面部分文字

以……方式省略,显示尾部文字内容。

labellineBreakMode = NSLineBreakByTruncatingMiddle;中间的内容

以……方式省略,显示头尾的文字内容。

labellineBreakMode = NSLineBreakByTruncatingTail;结尾部分的内容

以……方式省略,显示头的文字内容。

labellineBreakMode = NSLineBreakByWordWrapping;以单词为显示单位显

示,后面部分省略不显示。

有时,网络速度非常慢,为了节省资源,用户可以自己设置需要的网络超时时间。打开注册表编辑器,单击窗口左侧的树形列表,依次HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon子键,在其键值窗口中新建一个“DWORD值”类型的键值项,将其命名为“SlowLinkTimeOut”,设置键值为“3000”(单位是毫秒),重新启动电脑后,设置生效。

IOS 请求的get 和 post的请求的区别

1 get是从伺服器上获取资料,post是向伺服器传送资料。

2 get是把引数资料伫列加到提交表单的ACTION属性所指的URL中,值和表单内各个栏位一一对应,在URL中可以看到。post是通过>

根据个人的 *** 作习惯来决定,下面有办法:苹果手机 IOS 系统九宫格输入法,想必大家都非常期待了,苹果公司在最近发布的最新版本的 IOS 系统里加入了九宫格输入法,方便了我们输入汉字,笔者也在第一时间安装来体验了,确实不错,方便了很多,激动了吧?苹果手机如何升级IOS7工具/原料iphone 4siTunesWindows 81ios7 beta4固件文件方法/步骤1说明:1本方法主要是在还没有越狱的基础上实现的,如果已经越狱的朋友,可以查看其它资料。2本方法是进行固件刷机 *** 作,如果已经安装了 ios7 beta4 之前版本可以查看其它相关资料。2首先是下载 ios7 beta4 固件文件,如果有开发者账号的朋友可以直接去苹果的开发者中心进行下载,如果没有的朋友可以去iOS 7正式版官方下载在浏览器进而输入这个地址,就可以看到我们想要下载的固件了。固件文件有点大,请大家慢慢等待,如果网速快的好,可以忽略这句话。因为所使用的是 iphone 4s ,所在这里笔者选择的是 iphone 4s 的固件来进行下载。在这里有个问题,就是有些朋友说下载来的是固件是dmg格式,不能进行刷机,这是个问题,如果是从提供的这个网址去下载,下载来的固件文件就可以安装的,不用去提取里面的文件了。关于如何提取,请朋友去查看相关资料。3把苹果手机用数据线与电脑连接起来,并打开已经安装好的 iTunes 软件(关于如何安装 iTunes ,可以去查看相关资料),在打开的工作界面的右上角找到 iphone 并点击它打开。在打开的页面里我们就可以看到这时正在连接的苹果手机的一些相关的信息了,在这里请先按住键盘上的 Shift 键(mac系统请按 Option 键),再点击“检查更新”。注意:不是点击恢复。在d出的打开对话框里找到我们之前下载好的固件文件并选择它,然后点击打开。这时就会有提示说要把 ios 7 更新的 iphone 里了,点击“更新”。然后苹果手机自动重启,软件就开始提取文件并经过一系列自动的过程把 ios7 更新到苹果手机里了,这一过程是全自动的,不需要我们做什么,我们唯一要做的就是保证电源的正常。当更新完成之后就会d出一个提示已经更新完成的提示,并说手机已经开始重新启动了。当手机重启之后,就会有个首次使用的欢迎界面和设置过程,滑动之后的下一个界面点击“继续”。这里是提示我们是否要开启定位服务,笔者建议开启。这里是设置一个密码,你可以设置也可以不设置,因为笔者首次使用,所以就不设置了,进去使用了再设置吧。恭喜你,一切顺利,很成功,现在可以使用苹果的 ios7 系统了。查看手机关于里的版本是 7 了。注意事项保证电源正常,请勿断电保证苹果手机有充足的电量如果是固件文件是dmg格式的,记得把里面的ipsw格式的文件提取出来。

以上就是关于JAVA中如何获取毫秒和微秒数全部的内容,包括:JAVA中如何获取毫秒和微秒数、iOS开发中遇到的小问题-----总结、iOS 如何去设置网络超时时间+如何模拟等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9398370.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-27
下一篇2023-04-27

发表评论

登录后才能评论

评论列表(0条)

    保存