//// This code is part of Document Solutions for Word demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.Drawing;usingGrapeCity.Documents.Word;usingGrapeCity.Documents.Word.Fields;usingSystem.Globalization; namespaceDsWordWeb.Demos{// This sample shows how to add simple date and time fields to a Word document.publicclassDateAndTime {publicGcWordDocumentCreateDocx() {var doc = newGcWordDocument(); var date = newDateFieldOptions(doc); doc.Body.AddParagraph("DATE field with default formatting: ").AddComplexField(date); var time = newTimeFieldOptions(doc); doc.Body.AddParagraph("TIME field with default formatting: ").AddComplexField(time); doc.Body.AddParagraph("The following table demonstrates some custom date/time formats. " +"The left column shows the date/time format, the right column contains the calculated field value."); // Add and setup a table to contain the samples:var t = doc.Body.Tables.Add(0, 0); t.Style = doc.Styles.Add("Table style 1", StyleType.Table);foreach (var border in t.Style.Table.Borders) { border.LineStyle = LineStyle.Single; border.LineWidth = 0.5f; border.Color.RGB = Color.Black; }// Sample DATE formats:string[] sampleDateFormats = ["M/d/yyyy","dddd, MMMM dd, yyyy","MMMM d, yyyy","M/d/yy","yyyy-MM-dd","d-MMM-yy","M.d.yyyy","MMM. d, yy","d MMMM yyyy","MMMM yy","MMM-yy","M/d/yyyy h:mm am/pm","M/d/yyyy h:mm:ss am/pm","h:mm am/pm","h:mm:ss am/pm","HH:mm","'Today is 'MMMM d, yyyy", ];// Add the sample format strings and corresponding DATE fields:foreach (string fmt in sampleDateFormats) {var r = t.Rows.Add(fmt);var dfo = newDateFieldOptions(doc) { DateTimeFormat = fmt }; r.Cells.Add().GetRange().Paragraphs.First.AddComplexField(dfo); } // Update all fields using a specific culture: doc.UpdateFields(newGrapeCity.Documents.Word.Layout.WordLayoutSettings() { FontCollection = Util.FontCollection, Culture = CultureInfo.GetCultureInfo("en-US") });// Done:return doc; } }}