Created
July 25, 2012 07:56
-
-
Save joseph-montanez/3174992 to your computer and use it in GitHub Desktop.
Parse a date in Vala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main () { | |
print ("Please enter in a date to be parsed: "); | |
var readDate = stdin.read_line (); | |
if (readDate != null) { | |
var parsedDate = Date (); | |
parsedDate.set_parse (readDate); | |
if (parsedDate.valid ()) { | |
var output = new char[100]; | |
var format = "%c"; | |
var success = parsedDate.strftime (output, format); | |
if (success == 0) { | |
print ("Sorry, failed to format date...\n"); | |
} else { | |
var formattedOutput = ((string) output).chomp (); | |
print ("Parsed Date: '" + formattedOutput + "'\n"); | |
} | |
} else { | |
print ("Sorry, failed to parse date...\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment