• Qt时间&日期


    1.主要类:QDateTime

    2.获取日期:QDateTime time=QDateTime::currentDateTime();

    3.从时间中提取指定格式的字符串:QString strDate=time.toString("yyyy");

    4.格式字符串:

      

    QString QDateTime::toString ( const QString & format ) const
    
    Returns the datetime as a string. The format parameter determines the format of the result string.
    
    These expressions may be used for the date:
    
    Expression 	Output
    d 	the day as number without a leading zero (1 to 31)
    dd 	the day as number with a leading zero (01 to 31)
    ddd 	the abbreviated localized day name (e.g. 'Mon' to 'Sun'). Uses QDate::shortDayName().
    dddd 	the long localized day name (e.g. 'Monday' to 'Qt::Sunday'). Uses QDate::longDayName().
    M 	the month as number without a leading zero (1-12)
    MM 	the month as number with a leading zero (01-12)
    MMM 	the abbreviated localized month name (e.g. 'Jan' to 'Dec'). Uses QDate::shortMonthName().
    MMMM 	the long localized month name (e.g. 'January' to 'December'). Uses QDate::longMonthName().
    yy 	the year as two digit number (00-99)
    yyyy 	the year as four digit number
    
    These expressions may be used for the time:
    
    Expression 	Output
    h 	the hour without a leading zero (0 to 23 or 1 to 12 if AM/PM display)
    hh 	the hour with a leading zero (00 to 23 or 01 to 12 if AM/PM display)
    m 	the minute without a leading zero (0 to 59)
    mm 	the minute with a leading zero (00 to 59)
    s 	the second without a leading zero (0 to 59)
    ss 	the second with a leading zero (00 to 59)
    z 	the milliseconds without leading zeroes (0 to 999)
    zzz 	the milliseconds with leading zeroes (000 to 999)
    AP 	use AM/PM display. AP will be replaced by either "AM" or "PM".
    ap 	use am/pm display. ap will be replaced by either "am" or "pm".
    
    All other input characters will be ignored. Any sequence of characters that are enclosed in singlequotes will be treated as text and not be used as an expression. Two consecutive singlequotes ("''") are replaced by a singlequote in the output.
    
    Example format strings (assumed that the QDateTime is 21 May 2001 14:13:09):
    
    Format 	Result
    dd.MM.yyyy 	21.05.2001
    ddd MMMM d yy 	Tue May 21 01
    hh:mm:ss.zzz 	14:13:09.042
    h:m:s ap 	2:13:9 pm
  • 相关阅读:
    kubernetes入门(03)kubernetes的基本概念
    洛谷P3245 [HNOI2016]大数(莫队)
    洛谷P4462 [CQOI2018]异或序列(莫队)
    cf997C. Sky Full of Stars(组合数 容斥)
    cf1121F. Compress String(后缀自动机)
    洛谷P4704 太极剑(乱搞)
    洛谷P4926 [1007]倍杀测量者(差分约束)
    洛谷P4590 [TJOI2018]游园会(状压dp LCS)
    洛谷P4588 [TJOI2018]数学计算(线段树)
    洛谷P4592 [TJOI2018]异或(可持久化01Trie)
  • 原文地址:https://www.cnblogs.com/gisk/p/QtDataTime.html
Copyright © 2020-2023  润新知