Search code examples
python-2.7pyqt4

QDate.currentDate() display formatting


I need the date in a regular form.

Here when I use the below code:

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

date = QDate.currentDate()
print date

I get the below output:

PyQt4.QtCore.QDate(2014, 5, 23)

I want the date to be displayed in '/' or '.' eg.(5.23.2014)

Please suggest how to do it.


Solution

  • Check the docs:

    date = QDate.currentDate().toString("dd.MM.yyyy")
    print date
    2014.5.23
    

    To change:

    date = QDate.currentDate().toString("MM.dd.yyyy")
    print date
    05.23.2014