Object-C获取系统当前时间(指定格式)

代码如下:

        // 获取系统当前时间
        NSDate * date = [NSDate date];
        NSTimeInterval sec = [date timeIntervalSinceNow];
        NSDate * currentDate = [[NSDate alloc] initWithTimeIntervalSinceNow:sec];
        
        //设置时间输出格式:
        NSDateFormatter * df = [[NSDateFormatter alloc] init ];
        [df setDateFormat:@"yyyy年MM月dd日 HH小时mm分ss秒"];
        NSString * na = [df stringFromDate:currentDate];
        
        NSLog(@"系统当前时间为:%@",na);


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您想在VBA中模拟鼠标点击与指定路径图片一致的位置,可以使用以下代码: ```vb Sub ClickImage() Dim imagePath As String Dim x As Long, y As Long '指定图片路径 imagePath = "C:\image.png" '查找图片位置 If FindImage(imagePath, x, y) Then '模拟鼠标点击 MouseClick x, y Else MsgBox "未找到指定图片" End If End Sub Function FindImage(imagePath As String, ByRef x As Long, ByRef y As Long) As Boolean Dim i As Long, j As Long Dim imageWidth As Long, imageHeight As Long Dim screenWidth As Long, screenHeight As Long Dim screenBmp As Object, imageBmp As Object '获取屏幕和图片尺寸 screenWidth = Screen.Width \ Screen.TwipsPerPixelX screenHeight = Screen.Height \ Screen.TwipsPerPixelY Set screenBmp = CreateObject("GDIPlus.Bitmap") screenBmp.LockBits "rect=" & "0,0," & screenWidth & "," & screenHeight, 0, 24, VarPtr(Screen.Pixels(1, 1)), screenWidth * 3 Set imageBmp = CreateObject("GDIPlus.Bitmap").FromFile(imagePath) imageWidth = imageBmp.Width imageHeight = imageBmp.Height '在屏幕中查找图片 For i = 0 To screenWidth - imageWidth For j = 0 To screenHeight - imageHeight If CompareImage(screenBmp, imageBmp, i, j) Then x = i + imageWidth / 2 y = j + imageHeight / 2 FindImage = True Exit Function End If Next j Next i '释放资源 imageBmp.Dispose screenBmp.UnlockBits VarPtr(Screen.Pixels(1, 1)) End Function Function CompareImage(screenBmp As Object, imageBmp As Object, x As Long, y As Long) As Boolean Dim i As Long, j As Long Dim screenColor As Long, imageColor As Long '比较像素 For i = 0 To imageBmp.Width - 1 For j = 0 To imageBmp.Height - 1 screenColor = screenBmp.GetPixel(x + i, y + j) imageColor = imageBmp.GetPixel(i, j) If screenColor <> imageColor Then Exit Function End If Next j Next i CompareImage = True End Function Sub MouseClick(x As Long, y As Long) '模拟鼠标点击 mouse_event MOUSEEVENTF_LEFTDOWN, x, y, 0, 0 mouse_event MOUSEEVENTF_LEFTUP, x, y, 0, 0 End Sub ``` 这段代码会在屏幕中查找指定路径的图片,如果找到了就模拟鼠标点击图片中心位置。注意,这段代码需要引用Windows API,您需要在代码模块中添加以下代码段: ```vb Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值