'''' This code is part of Document Solutions for Word demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.DrawingImportsSystem.GlobalizationImportsGrapeCity.Documents.WordImportsGrapeCity.Documents.Word.Fields '' This sample shows how to add simple date and time fields to a Word document.PublicClassDateAndTimeFunctionCreateDocx() AsGcWordDocumentDim doc = NewGcWordDocument() Dim dateOpts = NewDateFieldOptions(doc) doc.Body.AddParagraph("DATE field with default formatting: ").AddComplexField(dateOpts) Dim timeOpts = NewTimeFieldOptions(doc) doc.Body.AddParagraph("TIME field with default formatting: ").AddComplexField(timeOpts) 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:Dim t = doc.Body.Tables.Add(0, 0) t.Style = doc.Styles.Add("Table style 1", StyleType.Table)ForEach border In t.Style.Table.Borders border.LineStyle = LineStyle.Single border.LineWidth = 0.5F border.Color.RGB = Color.BlackNext'' Sample DATE formats:Dim sampleDateFormats AsString() = {"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 fmt In sampleDateFormatsDim r = t.Rows.Add(NewString() {fmt})Dim dfo = NewDateFieldOptions(doc) With {.DateTimeFormat = fmt} r.Cells.Add().GetRange().Paragraphs.First.AddComplexField(dfo)Next '' Update all fields using a specific culture: doc.UpdateFields(NewGrapeCity.Documents.Word.Layout.WordLayoutSettings() With { .FontCollection = Util.FontCollection, .Culture = CultureInfo.GetCultureInfo("en-US") })'' Done:Return docEndFunctionEndClass