我想在iOS中获得时间/日期格式,比如几小时前,几天前.但是我得到了错误的数据.例如,如果时间是:
2015-10-21 03:43:20
Run Code Online (Sandbox Code Playgroud)
然后根据下面的代码,它显示我6小时前.我在php中使用Now()函数来保存时间/日期,那么我如何才能显示不同国家的确切时间?
+(NSString*)HourCalculation:(NSString*)PostDate
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormat setTimeZone:gmt];
NSDate *ExpDate = [dateFormat dateFromString:PostDate];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSDayCalendarUnit|NSWeekCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit|NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:ExpDate toDate:[NSDate date] options:0];
NSString *time;
if(components.year!=0)
{
if(components.year==1)
{
time=[NSString stringWithFormat:@"%ld year",(long)components.year];
}
else
{
time=[NSString stringWithFormat:@"%ld years",(long)components.year];
}
}
else if(components.month!=0)
{
if(components.month==1)
{
time=[NSString stringWithFormat:@"%ld month",(long)components.month];
}
else
{
time=[NSString stringWithFormat:@"%ld months",(long)components.month];
}
}
else if(components.week!=0) …Run Code Online (Sandbox Code Playgroud) 我在iOS中使用sqlite数据库.我在我的应用程序中使用了CURD操作.例如,将数据插入到我使用下面代码的数据库中.
- (BOOL) saveData:(User *)user
{
const char *dbpath = [databasePath UTF8String];
if (sqlite3_open(dbpath, &database) == SQLITE_OK)
{
if([self getUserData:user.email] != nil)
{
[self updateUserData:user];
return YES;
}
else
{
NSString *insertSQL = [NSString stringWithFormat:
@"insert into users(userid,name,email,password,address,age,gender,phone,qualification,role,createddate,apiKey,priorityid,usertype) values (\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\")",user.userid,user.name,user.email,user.password,user.address,user.age,user.gender,user.phone,user.qualification,user.role,user.createddate,user.api_key,user.priority_id,user.user_type];
NSLog(@"%@",insertSQL);
const char *insert_stmt = [insertSQL UTF8String];
sqlite3_prepare_v2(database, insert_stmt,-1, &statement, NULL);
if (sqlite3_step(statement) == SQLITE_DONE)
{
sqlite3_finalize(statement);
// sqlite3_close(database);
return YES;
}
else
{
NSLog(@"%serrr is ",sqlite3_errmsg(database));
//sqlite3_reset(statement);
sqlite3_close(database);
return NO;
}
}
}
//sqlite3_reset(statement);
sqlite3_close(database);
return NO;
}
Run Code Online (Sandbox Code Playgroud)
由于sqlite数据库,我的应用程序中出现了内存问题.我无法理解调用 …
我在我的应用程序中添加了谷歌地图。我在谷歌地图上显示当前位置。我现在在我的当前位置上显示一个红色标记,点击标记我想在弹出窗口中显示标记上方的地址,就像我们通常在应用程序中看到的那样。我尝试了一些方法,但没有一个对我有用。在这里分享代码。
1.我尝试的第一种方式
@Override
public void onLocationChanged(Location location) {
mMap.clear();
latitude = location.getLatitude();
longitude = location.getLongitude();
MarkerOptions mo=new MarkerOptions();
LatLng latLng = new LatLng(latitude, longitude);
marker=mMap.addMarker(mo.position(latLng));
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(15));
mo.title("Current Location");
}
Run Code Online (Sandbox Code Playgroud)
2.我尝试的第二种方式
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker arg0) {
String title = "Any Thing You want";
marker.setTitle(title);
return true;
}
});
Run Code Online (Sandbox Code Playgroud)
请告诉我在这里错在哪里。谢谢
我面临一个奇怪的问题。我用以下代码创建了UIPicker。我还使用了IQKeyboardManager来管理键盘。
let datepicker = UIPickerView()
datepicker.frame = CGRect(x: 0, y: -10, width: UIScreen.main.bounds.width, height: 200)
datepicker.backgroundColor = Constants.Colors.blue
datepicker.tintColor = UIColor.white
textfieldDropDown.inputView = datepicker
textfieldDropDown.inputView?.autoresizingMask = .flexibleHeight
datepicker.delegate = self
datepicker.reloadAllComponents()
Run Code Online (Sandbox Code Playgroud)
临时解决方案 如果我将高度设置为220,那么由于高度增加,它不会显示任何间隙。
请告诉我对此的最佳解决方案?
我用 ansible 编写了一个剧本任务。我能够在 Linux 端运行该剧本。
- name: Set paths for go
blockinfile:
path: $HOME/.profile
backup: yes
state: present
block: |
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export FABRIC_CFG_PATH=$HOME/.fabdep/config
- name: Load Env variables
shell: source $HOME/.profile
args:
executable: /bin/bash
register: source_result
become: yes
Run Code Online (Sandbox Code Playgroud)
与在 Linux 中一样,我们.profile在主目录中有,但在 Mac 中没有.profile,而.bash_profile在 macOS 中。
所以我想检查操作系统是否是Mac,那么路径应该是$HOME/.bash_profile,如果操作系统是基于Linux的,那么它应该寻找$HOME/.profile.
我尝试过添加
when: ansible_distribution == 'Ubuntu' and ansible_distribution_release == 'precise'
Run Code Online (Sandbox Code Playgroud)
但这首先行不通,而且是一个漫长的过程。我想获取基于变量中操作系统的路径并使用它。
谢谢
我正在尝试将 Node.js SDK 用于 BigchainDB,但我总是收到错误消息
错误:找不到模块“bigchaindb-driver”
但是bigchaindb-driver已经安装了npm install。
请检查这个github问题
我正在使用一个类我使用单例模式.我有静态方法.现在我想在静态方法中调用一个非静态方法.但是我无法调用它.请告诉我解决方案是什么.
#import "ThemeManager.h"
@implementation ThemeManager
+(ThemeManager *)sharedInstance
{
NSLog(@"shared instance called");
static ThemeManager *sharedInstance = nil;
if (sharedInstance == nil)
{
sharedInstance = [[ThemeManager alloc] init];
}
[self getPref];//i get error at this line
return sharedInstance;
}
-(void)getPref
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *themeName = [defaults objectForKey:@"theme"] ?: @"default";
NSLog(@"theme name is %@",themeName);
NSString *path = [[NSBundle mainBundle] pathForResource:themeName ofType:@"plist"];
self.theme = [NSDictionary dictionaryWithContentsOfFile:path];
}
@end
Run Code Online (Sandbox Code Playgroud) 我在iOS上使用代码在UI上显示标签,而不是在故事板上.当标签的大小很大,那么它确实显示它在视图之外,所以我决定sizeToFit在iOS中使用.但是当我在标签上应用这个东西时,它确实出现在视图上.请说明为什么我的标签在这种情况下不会出现.
以下是标签的代码:
self.label_company = [[UILabel alloc]initWithFrame:CGRectMake(60, 30, 150, 100)];
[self.label_company setFont:[UIFont fontWithName:@"HelveticaNeue" size:12]];
Run Code Online (Sandbox Code Playgroud) 我在UITextView里面加了一个UIView.UIView有一些高度取决于屏幕尺寸.UITextView可以有更多或更少的文字.所以我想制作UITextView动态的高度,所以如果文本更多,那么它应该有更多的高度,但它应该小于主视图的高度.如果文字少于那么它的高度应该更少.
我有一个 UILabel 我想将它的某些部分作为下划线。我正在使用下面的代码。但它强调整个标签而不是标签的某些部分。请告诉我如何使标签的某些部分成为下划线。
let attributedString = NSMutableAttributedString(string: "UserAgreement".localized)
attributedString.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.styleSingle.rawValue, range: NSRange(location: 0, length: 10))
labelTc.attributedText = attributedString
Run Code Online (Sandbox Code Playgroud)
我不想处理故事板
ios ×6
objective-c ×4
swift ×2
android ×1
ansible ×1
bigchaindb ×1
blockchain ×1
cocoa-touch ×1
google-maps ×1
ios11 ×1
ipad ×1
iphone ×1
linux ×1
macos ×1
node.js ×1
npm ×1
oop ×1
range ×1
shell ×1
sqlite ×1
string ×1
timezone ×1
toolbar ×1
uilabel ×1