什么是日期格式

时间:2016-06-14 06:10:01

标签: ios objective-c

“06/08/2016 09:50:12”的日期和时间格式是什么,要转换为“dd MMMM YYYY HH:mm”?,我将NSDate转换为NSString。

4 个答案:

答案 0 :(得分:2)

使用此代码,

NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
NSString *result = [dateFormat stringFromDate:date];

它为我工作,希望它有用。

答案 1 :(得分:0)

试试这段代码:

NSDateFormatter *format= [[NSDateFormatter alloc] init];
[format setDateFormat:@"dd/MM/yyyy HH:mm:ss"];

// string to date
NSString *dateStr = @"06/08/2016 01:50:12";
NSDate *date = [format dateFromString:dateStr];

// date to string
[format setDateFormat:@"dd MMMM yyyy HH:mm"];
NSString *dateStr2 = [format stringFromDate:date];
NSLog(@"%@", dateStr2);

答案 2 :(得分:-1)

试试这个,

 $con = new mysqli("localhost", "root", "", "survey");
if ($con) {
    printf("");
}
$query = "SELECT AVG(workarea),AVG(manager),AVG(comm) FROM score;";
// Execute multi query
if ($result = $con->query($query)) {

    /* fetch object array */
    while ($row = $result->fetch_row()) {
        ?>
        <div class="row count">
            WORK AREA/UNIT SCORE : <?php echo $row[0]; ?> 
        </div>

        <div class="row count">
            SUPERVISOR/MANAGER SCORE : <?php echo $row[1]; ?>    
        </div>

        <div class="row count">
            COMMUNICATION SCORE : <?php echo $row[2]; ?> 
        </div>
        <?php
    }

    /* free result set */
    $result->close();
}

将此日期转换为字符串:

    NSString *strDate = @"06/08/2016 09:50:12";
    NSDateFormatter *format= [[NSDateFormatter alloc] init];
    [format setDateFormat:@"dd/MM/YYYY HH:mm:s"];
    NSDate *date = [format dateFromString:strDate];
    NSLog(@"%@",date);

希望这个帮助

答案 3 :(得分:-1)

NSDateFormatter *format= [[NSDateFormatter alloc] init];
[format setDateFormat:@"dd/MM/YYYY HH:mm:ss"];

// string to date
NSString *dateStr = @"06/08/2016 01:50:12";
NSDate *date = [format dateFromString:dateStr];
NSLog(@"%@", date);

// date to string
NSDate *date2 = [NSDate date];
NSString *dateStr2 = [format stringFromDate:date2];
NSLog(@"%@", dateStr2);

//@"dd/MM/YYYY HH:mm:ss"
//dd is for the day.
//MM is for the month.
//YYYY is for the year.
//HH is for the hour.
//mm is for the minute.
//ss is for the second.