Whatever message this page gives is out now! Go check it out!
TimeFormat(time [, mask ])Parameter | Description |
time | A date/time value or string to convert |
mask | Masking characters that determine the format:
|
<cfscript>
todaydate = Now();
writeOutput(TimeFormat(todaydate));
</cfscript><cfscript>
writeoutput(timeFormat(now(), "hh:mm:ss, z"));
writeoutput(timeFormat(now(), "hh:mm:ss, Z"));
writeoutput(timeFormat(now(), "hh:mm:ss, X"));
writeoutput(timeFormat(now(), "hh:mm:ss, XX"));
writeoutput(timeFormat(now(), "hh:mm:ss, XXX"));
</cfscript><cfscript>
myDateTime = now();
WriteOutput(timeFormat(myDateTime,"hh:mm:ss,k" & "<br/>"));
WriteOutput(timeFormat(myDateTime,"hh:mm:ss,K" & "<br/>"));
</cfscript><cfscript>
// Simple Business Hours Display with TimeFormat
// Business: Multi-location retail with customer-friendly operating hours display
// Store locations with operating hours (from database)
storeLocations = [
{
"storeName": "Downtown Main Store",
"openTime": "08:00:00",
"closeTime": "22:00:00",
"phoneNumber": "(555) 123-4567"
},
{
"storeName": "Westfield Mall Location",
"openTime": "10:00:00",
"closeTime": "21:00:00",
"phoneNumber": "(555) 234-5678"
},
{
"storeName": "Airport Terminal Store",
"openTime": "06:30:00",
"closeTime": "23:30:00",
"phoneNumber": "(555) 345-6789"
}
];
// Function to check if store is currently open
function isStoreOpen(openTime, closeTime) {
local.currentTime = TimeFormat(Now(), "HH:nn");
local.storeOpen = TimeFormat(ParseDateTime(openTime), "HH:nn");
local.storeClose = TimeFormat(ParseDateTime(closeTime), "HH:nn");
return (local.currentTime GTE local.storeOpen AND local.currentTime LTE local.storeClose);
}
// Function to get next opening time
function getNextOpenTime(openTime, isOpen) {
if (isOpen) {
return "Currently Open";
} else {
return "Opens at " & TimeFormat(ParseDateTime(openTime), "h:nn tt");
}
}
</cfscript>
<cfoutput>
<h1>🏢 TimeFormat: Business Hours Display Demo</h1>
<p><strong>Business Need:</strong> Display store hours in customer-friendly formats across all channels</p>
<p><strong>Challenge:</strong> Raw database times (24-hour format) are not user-friendly</p>
<p><strong>Solution:</strong> Use TimeFormat() to convert times to appropriate display formats</p>
<p><strong>Current Time:</strong> <span style="color: blue; font-weight: bold;">#TimeFormat(Now(), "h:nn:ss tt")#</span></p>
<hr>
<h2>Store Locations & Hours</h2>
</cfoutput>
<cfloop array="#storeLocations#" index="store">
<cfscript>
// Check if store is currently open
storeIsOpen = isStoreOpen(store["openTime"], store["closeTime"]);
// Format hours for different contexts
websiteHours = TimeFormat(store["openTime"], "h:nn tt") & " - " & TimeFormat(store["closeTime"], "h:nn tt");
mobileHours = TimeFormat(store["openTime"], "h:nn tt") & " - " & TimeFormat(store["closeTime"], "h:nn tt");
employeeSchedule = TimeFormat(store["openTime"], "HH:nn") & " - " & TimeFormat(store["closeTime"], "HH:nn");
// Get status message
statusMessage = getNextOpenTime(store["openTime"], storeIsOpen);
</cfscript>
<cfoutput>
<div style="background: #storeIsOpen ? '##d4edda' : '##fff3cd'#; padding: 20px; margin: 15px 0; border-radius: 8px; border-left: 5px solid #storeIsOpen ? '##28a745' : '##ffc107'#;">
<h3>#store["storeName"]#</h3>
<p><strong>Phone:</strong> #store["phoneNumber"]#</p>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 15px 0;">
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h4>🌐 Website Display</h4>
<p style="font-size: 1.3em; color: ##007bff; font-weight: bold;">#websiteHours#</p>
<p><em>Customer-friendly 12-hour format</em></p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h4>📱 Mobile App</h4>
<p style="font-size: 1.3em; color: ##28a745; font-weight: bold;">#mobileHours#</p>
<p><em>Compact format for small screens</em></p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h4>👥 Employee Schedule</h4>
<p style="font-size: 1.3em; color: ##6f42c1; font-weight: bold;">#employeeSchedule#</p>
<p><em>24-hour format for staff clarity</em></p>
</div>
</div>
<div style="background: rgba(255,255,255,0.7); padding: 15px; border-radius: 5px; margin-top: 15px;">
<cfif storeIsOpen>
<p style="color: green; font-weight: bold; font-size: 1.1em;">
✅ OPEN NOW - Closes at #TimeFormat(store["closeTime"], "h:nn tt")#
</p>
<p>🛒 <em>Visit us today for great deals and excellent service!</em></p>
<cfelse>
<p style="color: orange; font-weight: bold; font-size: 1.1em;">
🔒 CURRENTLY CLOSED - #statusMessage#
</p>
<p>📞 <em>Call us during business hours or visit our website anytime!</em></p>
</cfif>
</div>
</div>
</cfoutput>
</cfloop>
<cfscript>
// Calculate store statistics
totalStores = ArrayLen(storeLocations);
openStores = 0;
for (location in storeLocations) {
if (isStoreOpen(location["openTime"], location["closeTime"])) {
openStores++;
}
}
// Sample special hours (holidays, events)
specialHours = [
{"date": "Black Friday", "hours": "06:00:00 - 23:59:59"},
{"date": "Christmas Eve", "hours": "08:00:00 - 18:00:00"},
{"date": "New Year's Day", "hours": "12:00:00 - 20:00:00"}
];
</cfscript>
<cfoutput>
<h2>📊 Store Status Summary</h2>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; margin: 20px 0;">
<div style="background: ##e8f5e8; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Total Stores</h3>
<h2 style="color: blue;">#totalStores#</h2>
</div>
<div style="background: ##d4edda; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Currently Open</h3>
<h2 style="color: green;">#openStores#</h2>
</div>
<div style="background: ##fff3cd; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Closed Now</h3>
<h2 style="color: orange;">#totalStores - openStores#</h2>
</div>
</div>
<h2>🎯 Special Hours & Events</h2>
<div style="background: ##e3f2fd; padding: 20px; border-radius: 8px; margin: 20px 0;">
<h3>Upcoming Special Operating Hours:</h3>
<cfloop array="#specialHours#" index="special">
<cfscript>
// Parse and format special hours
hoursParts = ListToArray(special["hours"], " - ");
if (ArrayLen(hoursParts) EQ 2) {
openSpecial = TimeFormat(ParseDateTime(hoursParts[1]), "h:nn tt");
closeSpecial = TimeFormat(ParseDateTime(hoursParts[2]), "h:nn tt");
formattedSpecialHours = openSpecial & " - " & closeSpecial;
} else {
formattedSpecialHours = special["hours"];
}
</cfscript>
<div style="background: white; padding: 15px; margin: 10px 0; border-left: 4px solid ##007bff; border-radius: 5px;">
<h4>#special["date"]#</h4>
<p style="font-size: 1.2em; color: ##007bff; font-weight: bold;">#formattedSpecialHours#</p>
<p><em>All locations will follow these special hours</em></p>
</div>
</cfloop>
</div>
</cfoutput><cfscript>
// Simple Event Scheduling with TimeFormat
// Business: Professional appointment booking and event management system
// Today's scheduled events/appointments
todaysEvents = [
{
"eventTitle": "Medical Consultation - Dr. Smith",
"startTime": "09:30:00",
"duration": 30,
"clientName": "Sarah Johnson",
"type": "Medical"
},
{
"eventTitle": "Project Strategy Meeting",
"startTime": "14:15:00",
"duration": 90,
"clientName": "Tech Corp Team",
"type": "Business"
},
{
"eventTitle": "Webinar: Digital Marketing Trends",
"startTime": "16:00:00",
"duration": 60,
"clientName": "Global Audience",
"type": "Webinar"
},
{
"eventTitle": "Customer Support Training",
"startTime": "11:00:00",
"duration": 45,
"clientName": "Support Team",
"type": "Training"
}
];
// Function to calculate end time
function calculateEndTime(startTime, durationMinutes) {
local.startObj = ParseDateTime(startTime);
local.endObj = DateAdd("n", durationMinutes, local.startObj);
return local.endObj;
}
// Function to get event status based on current time
function getEventStatus(startTime, duration) {
local.now = Now();
local.startObj = ParseDateTime(startTime);
local.endObj = DateAdd("n", duration, local.startObj);
if (local.now LT local.startObj) {
return "Upcoming";
} else if (local.now GTE local.startObj AND local.now LTE local.endObj) {
return "In Progress";
} else {
return "Completed";
}
}
// Function to get time until event
function getTimeUntilEvent(startTime) {
local.now = Now();
local.startObj = ParseDateTime(startTime);
local.diffMinutes = DateDiff("n", local.now, local.startObj);
if (local.diffMinutes GT 60) {
return Int(local.diffMinutes / 60) & " hours " & (local.diffMinutes MOD 60) & " minutes";
} else if (local.diffMinutes GT 0) {
return local.diffMinutes & " minutes";
} else {
return "Started";
}
}
</cfscript>
<cfoutput>
<h1>📅 TimeFormat: Event Scheduling & Appointments Demo</h1>
<p><strong>Business Need:</strong> Professional event scheduling with clear time displays for all stakeholders</p>
<p><strong>Challenge:</strong> Different contexts require different time formats for optimal user experience</p>
<p><strong>Solution:</strong> Use TimeFormat() to present times appropriately for each audience</p>
<p><strong>Current Time:</strong> <span style="color: blue; font-weight: bold;">#TimeFormat(Now(), "h:nn:ss tt")#</span></p>
<hr>
<h2>Today's Event Schedule</h2>
</cfoutput>
<cfloop array="#todaysEvents#" index="event">
<cfscript>
// Calculate event details
endTime = calculateEndTime(event["startTime"], event["duration"]);
eventStatus = getEventStatus(event["startTime"], event["duration"]);
timeUntil = getTimeUntilEvent(event["startTime"]);
// Format times for different contexts
invitationTime = TimeFormat(event["startTime"], "h:nn tt");
calendarTime = TimeFormat(event["startTime"], "HH:nn");
reminderTime = TimeFormat(event["startTime"], "h:nn tt");
endTimeFormatted = TimeFormat(endTime, "h:nn tt");
// Set status styling
statusClass = "";
statusIcon = "";
switch(eventStatus) {
case "Upcoming":
statusClass = "##fff3cd";
statusIcon = "⏳";
break;
case "In Progress":
statusClass = "##d4edda";
statusIcon = "▶️";
break;
case "Completed":
statusClass = "##e2e3e5";
statusIcon = "✅";
break;
}
</cfscript>
<cfoutput>
<div style="background: #statusClass#; padding: 20px; margin: 15px 0; border-radius: 8px; border-left: 5px solid ##007bff;">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;">
<h3 style="margin: 0;">#event["eventTitle"]#</h3>
<span style="background: white; padding: 5px 15px; border-radius: 15px; font-weight: bold;">
#statusIcon# #eventStatus#
</span>
</div>
<p><strong>Client/Attendee:</strong> #event["clientName"]# | <strong>Type:</strong> #event["type"]# | <strong>Duration:</strong> #event["duration"]# minutes</p>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 15px 0;">
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h4>📧 Email Invitation</h4>
<p style="font-size: 1.3em; color: ##007bff; font-weight: bold;">#invitationTime# - #endTimeFormatted#</p>
<p><em>User-friendly 12-hour format</em></p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h4>📱 Mobile Reminder</h4>
<p style="font-size: 1.3em; color: ##28a745; font-weight: bold;">#reminderTime#</p>
<p><em>Compact notification format</em></p>
</div>
<div style="background: white; padding: 15px; border-radius: 5px; text-align: center;">
<h4>🗓️ Calendar Export</h4>
<p style="font-size: 1.3em; color: ##6f42c1; font-weight: bold;">#calendarTime# - #TimeFormat(endTime, "HH:nn")#</p>
<p><em>24-hour format for calendar apps</em></p>
</div>
</div>
<div style="background: rgba(255,255,255,0.7); padding: 15px; border-radius: 5px;">
<cfif eventStatus EQ "Upcoming">
<p style="color: ##856404; font-weight: bold;">
⏰ <strong>Starts in #timeUntil#</strong>
</p>
<p>📱 <em>Mobile Reminder: "#event["eventTitle"]# starts at #reminderTime#"</em></p>
<cfelseif eventStatus EQ "In Progress">
<p style="color: ##155724; font-weight: bold;">
🔴 <strong>Currently in session until #endTimeFormatted#</strong>
</p>
<p>💼 <em>Meeting in progress - do not disturb</em></p>
<cfelse>
<p style="color: ##6c757d; font-weight: bold;">
✅ <strong>Event completed successfully</strong>
</p>
<p>📝 <em>Follow-up actions and notes can be added</em></p>
</cfif>
</div>
</div>
</cfoutput>
</cfloop>
<cfscript>
// Calculate event statistics
totalEvents = ArrayLen(todaysEvents);
upcomingEvents = 0;
inProgressEvents = 0;
completedEvents = 0;
for (eventItem in todaysEvents) {
status = getEventStatus(eventItem["startTime"], eventItem["duration"]);
switch(status) {
case "Upcoming": upcomingEvents++; break;
case "In Progress": inProgressEvents++; break;
case "Completed": completedEvents++; break;
}
}
// Sample appointment booking slots for tomorrow
availableSlots = [
"09:00:00", "09:30:00", "10:00:00", "10:30:00",
"14:00:00", "14:30:00", "15:00:00", "15:30:00", "16:00:00"
];
</cfscript>
<cfoutput>
<h2>📊 Event Status Dashboard</h2>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 15px; margin: 20px 0;">
<div style="background: ##e8f5e8; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Total Events</h3>
<h2 style="color: blue;">#totalEvents#</h2>
</div>
<div style="background: ##fff3cd; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Upcoming</h3>
<h2 style="color: orange;">#upcomingEvents#</h2>
</div>
<div style="background: ##d4edda; padding: 15px; text-align: center; border-radius: 8px;">
<h3>In Progress</h3>
<h2 style="color: green;">#inProgressEvents#</h2>
</div>
<div style="background: ##e2e3e5; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Completed</h3>
<h2 style="color: gray;">#completedEvents#</h2>
</div>
</div>
<h2>📅 Available Appointment Slots (Tomorrow)</h2>
<div style="background: ##e3f2fd; padding: 20px; border-radius: 8px;">
<h3>Book Your Next Appointment:</h3>
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 15px 0;">
<cfloop array="#availableSlots#" index="slot">
<cfscript>
customerSlot = TimeFormat(slot, "h:nn tt");
adminSlot = TimeFormat(slot, "HH:nn");
</cfscript>
<div style="background: white; padding: 10px; text-align: center; border: 2px solid ##007bff; border-radius: 5px; cursor: pointer;">
<p style="margin: 5px 0; font-weight: bold; color: ##007bff;">#customerSlot#</p>
<p style="margin: 5px 0; font-size: 0.8em; color: ##6c757d;">(#adminSlot#)</p>
</div>
</cfloop>
</div>
<p style="background: ##f8f9fa; padding: 10px; border-radius: 5px; margin-top: 15px;">
<strong>Booking Confirmation:</strong> "Your appointment is scheduled for [selected time] tomorrow. You will receive a reminder 1 hour before your appointment."
</p>
</div>
</cfoutput><!--- Simple TimeFormat Demo: E-Commerce Order Management --->
<cfscript>
// Sample order data
orderData = [
{"orderId": "ORD-001", "customerName": "Sarah Johnson", "orderTime": "08:15:30", "deliveryTime": "17:00:00", "status": "Processing"},
{"orderId": "ORD-002", "customerName": "Mike Brown", "orderTime": "11:45:15", "deliveryTime": "15:30:00", "status": "Out for Delivery"},
{"orderId": "ORD-003", "customerName": "Lisa Chen", "orderTime": "09:22:00", "deliveryTime": "19:00:00", "status": "Delivered"}
];
// Available delivery slots
timeSlots = ["09:00:00", "12:00:00", "15:00:00", "18:00:00"];
</cfscript>
<h1>🛒 TimeFormat: E-Commerce Order Management</h1>
<cfoutput>
<p><strong>Current Time:</strong> #TimeFormat(Now(), "h:nn:ss tt")#</p>
<hr>
<h2>📦 Order Processing Dashboard</h2>
<!--- Order 1 --->
<div style="background: ##f8f9fa; padding: 20px; margin: 15px 0; border-radius: 8px; border-left: 4px solid ##007bff;">
<h3>Order #orderData[1]["orderId"]#</h3>
<p><strong>Customer:</strong> #orderData[1]["customerName"]#</p>
<p><strong>Status:</strong> #orderData[1]["status"]#</p>
<hr>
<h4>📧 Customer Email Format:</h4>
<p style="background: ##e7f3ff; padding: 10px; border-radius: 5px;">
"Your order was placed at <strong>#TimeFormat(orderData[1]["orderTime"], "h:nn tt")#</strong> and will be delivered by <strong>#TimeFormat(orderData[1]["deliveryTime"], "h:nn tt")#</strong>."
</p>
<h4>🚛 System Logistics Format:</h4>
<p style="background: ##fff3e0; padding: 10px; border-radius: 5px;">
"Order timestamp: <strong>#TimeFormat(orderData[1]["orderTime"], "HH:nn:ss")#</strong> | Delivery ETA: <strong>#TimeFormat(orderData[1]["deliveryTime"], "HH:nn")#</strong>"
</p>
<h4>📱 Mobile App Format:</h4>
<p style="background: ##f3e5f5; padding: 10px; border-radius: 5px;">
"Ordered: <strong>#TimeFormat(orderData[1]["orderTime"], "h:nn tt")#</strong> → Arriving: <strong>#TimeFormat(orderData[1]["deliveryTime"], "h:nn tt")#</strong>"
</p>
</div>
<!--- Order 2 --->
<div style="background: ##f8f9fa; padding: 20px; margin: 15px 0; border-radius: 8px; border-left: 4px solid ##007bff;">
<h3>Order #orderData[2]["orderId"]#</h3>
<p><strong>Customer:</strong> #orderData[2]["customerName"]#</p>
<p><strong>Status:</strong> #orderData[2]["status"]#</p>
<hr>
<h4>📧 Customer Email Format:</h4>
<p style="background: ##e7f3ff; padding: 10px; border-radius: 5px;">
"Your order was placed at <strong>#TimeFormat(orderData[2]["orderTime"], "h:nn tt")#</strong> and will be delivered by <strong>#TimeFormat(orderData[2]["deliveryTime"], "h:nn tt")#</strong>."
</p>
<h4>🚛 System Logistics Format:</h4>
<p style="background: ##fff3e0; padding: 10px; border-radius: 5px;">
"Order timestamp: <strong>#TimeFormat(orderData[2]["orderTime"], "HH:nn:ss")#</strong> | Delivery ETA: <strong>#TimeFormat(orderData[2]["deliveryTime"], "HH:nn")#</strong>"
</p>
<h4>📱 Mobile App Format:</h4>
<p style="background: ##f3e5f5; padding: 10px; border-radius: 5px;">
"Ordered: <strong>#TimeFormat(orderData[2]["orderTime"], "h:nn tt")#</strong> → Arriving: <strong>#TimeFormat(orderData[2]["deliveryTime"], "h:nn tt")#</strong>"
</p>
</div>
<!--- Order 3 --->
<div style="background: ##f8f9fa; padding: 20px; margin: 15px 0; border-radius: 8px; border-left: 4px solid ##007bff;">
<h3>Order #orderData[3]["orderId"]#</h3>
<p><strong>Customer:</strong> #orderData[3]["customerName"]#</p>
<p><strong>Status:</strong> #orderData[3]["status"]#</p>
<hr>
<h4>📧 Customer Email Format:</h4>
<p style="background: ##e7f3ff; padding: 10px; border-radius: 5px;">
"Your order was placed at <strong>#TimeFormat(orderData[3]["orderTime"], "h:nn tt")#</strong> and will be delivered by <strong>#TimeFormat(orderData[3]["deliveryTime"], "h:nn tt")#</strong>."
</p>
<h4>🚛 System Logistics Format:</h4>
<p style="background: ##fff3e0; padding: 10px; border-radius: 5px;">
"Order timestamp: <strong>#TimeFormat(orderData[3]["orderTime"], "HH:nn:ss")#</strong> | Delivery ETA: <strong>#TimeFormat(orderData[3]["deliveryTime"], "HH:nn")#</strong>"
</p>
<h4>📱 Mobile App Format:</h4>
<p style="background: ##f3e5f5; padding: 10px; border-radius: 5px;">
"Ordered: <strong>#TimeFormat(orderData[3]["orderTime"], "h:nn tt")#</strong> → Arriving: <strong>#TimeFormat(orderData[3]["deliveryTime"], "h:nn tt")#</strong>"
</p>
</div>
<h2>📊 Simple Analytics</h2>
<div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin: 20px 0;">
<div style="background: ##e8f5e8; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Total Orders</h3>
<h2 style="color: blue;">#ArrayLen(orderData)#</h2>
</div>
<div style="background: ##fff3cd; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Processing</h3>
<h2 style="color: orange;">1</h2>
</div>
<div style="background: ##d4edda; padding: 15px; text-align: center; border-radius: 8px;">
<h3>Delivered</h3>
<h2 style="color: green;">1</h2>
</div>
</div>
<h2>📅 Available Time Slots</h2>
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 15px; margin: 20px 0;">
<div style="background: ##d4edda; padding: 15px; text-align: center; border-radius: 8px;">
<p style="font-weight: bold; margin: 0;">#TimeFormat(timeSlots[1], "h:nn tt")#</p>
<p style="margin: 5px 0; font-size: 0.9em;">Available</p>
</div>
<div style="background: ##d4edda; padding: 15px; text-align: center; border-radius: 8px;">
<p style="font-weight: bold; margin: 0;">#TimeFormat(timeSlots[2], "h:nn tt")#</p>
<p style="margin: 5px 0; font-size: 0.9em;">Available</p>
</div>
<div style="background: ##d4edda; padding: 15px; text-align: center; border-radius: 8px;">
<p style="font-weight: bold; margin: 0;">#TimeFormat(timeSlots[3], "h:nn tt")#</p>
<p style="margin: 5px 0; font-size: 0.9em;">Available</p>
</div>
<div style="background: ##d4edda; padding: 15px; text-align: center; border-radius: 8px;">
<p style="font-weight: bold; margin: 0;">#TimeFormat(timeSlots[4], "h:nn tt")#</p>
<p style="margin: 5px 0; font-size: 0.9em;">Available</p>
</div>
</div>
</cfoutput>