Aspose::Words::Properties::DocumentProperty::ToDateTime method

DocumentProperty::ToDateTime method

Returns the property value as DateTime in UTC.

System::DateTime Aspose::Words::Properties::DocumentProperty::ToDateTime()

Remarks

Throws an exception if the property type is not DateTime.

Microsoft Word stores only the date part (no time) for custom date properties.

Examples

Shows how to create a custom document property which contains a date and time.

auto doc = System::MakeObject<Aspose::Words::Document>();

doc->get_CustomDocumentProperties()->Add(u"AuthorizationDate", System::DateTime::get_Now());
System::DateTime authorizationDate = doc->get_CustomDocumentProperties()->idx_get(u"AuthorizationDate")->ToDateTime();
std::cout << System::String::Format(u"Document authorized on {0}", authorizationDate) << std::endl;

Shows various type conversion methods of custom document properties.

auto doc = System::MakeObject<Aspose::Words::Document>();
System::SharedPtr<Aspose::Words::Properties::CustomDocumentProperties> properties = doc->get_CustomDocumentProperties();

System::DateTime authDate = System::DateTime::get_Today();
properties->Add(u"Authorized", true);
properties->Add(u"Authorized By", System::String(u"John Doe"));
properties->Add(u"Authorized Date", authDate);
properties->Add(u"Authorized Revision", doc->get_BuiltInDocumentProperties()->get_RevisionNumber());
properties->Add(u"Authorized Amount", 123.45);

ASPOSE_ASSERT_EQ(properties->idx_get(u"Authorized")->ToBool(), true);
ASSERT_EQ(System::ObjectExt::ToString(properties->idx_get(u"Authorized By")), u"John Doe");
ASSERT_EQ(properties->idx_get(u"Authorized Date")->ToDateTime(), authDate);
ASSERT_EQ(properties->idx_get(u"Authorized Revision")->ToInt(), 1);
ASPOSE_ASSERT_EQ(properties->idx_get(u"Authorized Amount")->ToDouble(), 123.45);

See Also